File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFrame problem

 
Roldan Baldo
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats wrong with my code, ive got a problem, it shows a blank frame, but when i resize it, the button and the textfield will appear

 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are constructing your GUI after the frame is made visible, and never re-validating it (and another nono is you are doing it outside the event dispatch thread but that is minor).

Reorder the code so the JPanel is made and added to the Frame before the frame.setVisible() method is called. You should also set the size of the Frame before making it visible.
 
Rob Spoor
Sheriff
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call frame.pack(). It will set the size automatically to its preferred size. And also move the setVisible(true) call to the end as Steve suggested.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47216
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing Forum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic