This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in loading swing GUI components " Watch "Problem in loading swing GUI components " New topic

Problem in loading swing GUI components

Aos Khalifa

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

Joined: Jan 28, 2003
Posts: 3970

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.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36579
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:
subject: Problem in loading swing GUI components
Similar Threads
online help document problem
Timestamp Converter Applet
Is it possible to change the cursor with onMouseOver...
Mouse events on transparent Swing components
Drop Down Menu Buttons