• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in loading swing GUI components

 
Aos Khalifa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic