Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

Problem with images

Thread view: 
gaijinco - 09 Nov 2007 06:31 GMT
Hi!

I'm having a really frustrating problem with displaying images: the
problem is that when I created a GUI (using swing) the images doesn't
appears until I made the slightest change to the size of the window.

For the image, I'm using a JLabel with the setIcon() method.

I have tried all kinds of Layout Managers and all kind of combinations
of sizes for all elements (JFrame, JPanel's, JLabel's, etc) but
nothing seems to work.

Does somebody knows what may be happening?

Thank you very much!

This is my exact code:

public class InterfazCrucigrama extends JFrame {

    private JLabel panelImagen;

    public InterfazCrucigrama()    {
      setTitle( "Crucigrama" );
          getContentPane( ).setLayout( new BorderLayout(10,10) );
          setSize( 800, 600 );
          setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          setVisible(true);

          panelImagen = new JLabel("");
          panelImagen.setIcon(new ImageIcon("data/imagenes/
titulo.png"));
          getContentPane().add(panelImagen, BorderLayout.NORTH);
    }

    public static void main(String[] args) {
        InterfazCrucigrama miCrucigrama = new InterfazCrucigrama();
    }
}
Mark Space - 09 Nov 2007 06:59 GMT
> Hi!
>
[quoted text clipped - 35 lines]
>     }
> }

I'm not an expert, but I think you have "setVisible" in the wrong spot.
 Call that after all of the components get added.

Also, call pack() before setVisible but after all of the other
components have been added. pack() is the standard way of telling a
window that it's about ready to be drawn.
Andrew Thompson - 09 Nov 2007 07:01 GMT
...
>Does somebody knows what may be happening?

Images are loaded asynchronously (after you first
ask for them).

Knute Johnson has some good examples of image
loading on his site.
<http://rabbitbrush.frazmtn.com/>

Check particularly the 'ImageObserver JApplet' link under
'How to load images'.  I think that one will be close to
what you need.

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.