This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JFrame problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame problem" Watch "JFrame problem" New topic
Author

JFrame problem

Roldan Baldo
Ranch Hand

Joined: Aug 11, 2009
Posts: 99
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20131
    
  30

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44530
    
  34
Moving to Swing Forum
 
 
subject: JFrame problem
 
It's not a secret anymore!