wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Problem in loading swing GUI components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in loading swing GUI components " Watch "Problem in loading swing GUI components " New topic
Author

Problem in loading swing GUI components

Aos Khalifa
Greenhorn

Joined: Mar 18, 2012
Posts: 5
Hello guys,
I have this problem , When i run my java app ,sometimes it doesn't load GUI components till i focus it or move the mouse over it .
ex : I have a JButton , sometimes it appears correctly and sometimes I have to move the mouse over it to be displayed .

any solution please ??

Thanks .....
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

You probably need to show a simple example (the absolute minimum required to reproduce the problem). My guess is that you are putting up your main frame, then building the area that has your JButton in it in the main thread (or at least not the EDT/GUI thread), and so the GUI doesn't see it/respond to its presence until it is forced to re-paint that area of the screen. All your GUI code should be done in the Event Dispatch Thread (EDT/GUI thread). SwingUtilities has a few methods (invokeLater() and invokeAndWait()) which may help you with this.

All that is a guess, though. We need to see your code to do anything but guess.


Steve
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
Always ensure the setVisible(true) call appears after all add method invocations, setSize, etc., etc.

I think this discussion would fit better in our GUIs forum, so I shall move it thither.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in loading swing GUI components
 
Similar Threads
Timestamp Converter Applet
Drop Down Menu Buttons
Mouse events on transparent Swing components
Is it possible to change the cursor with onMouseOver...
online help document problem