• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFrame doesn't display components at first

 
Jos� Alberto Mu�iz Navarro
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day. I have an application to write and read a file. However, when the JFrame displays, it is SOMETIMES just an empty JFrame. If you resize it or move it, then the components (Some Checkboxes and a JButton) appear.
I have no idea about what it could be. Could you please help me?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose,
It looks fine to me. You may want to pack() the contents of the frame before you display it. That may help.
 
Jos� Alberto Mu�iz Navarro
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It didn't work :S It still does the same thing. I repeat, only the JFrame appears but it is blank. Nothing appears inside. Just as if you had displayed a blank frame. However, if I resize the window (even to make it smaller... or making it bigger and then adjusting it to the previous size), all the components appear, although they previously had had the space to display them.
It's not a matter of the components not having enough space (I think). Otherwise the pack() would have solved it, am I wrong?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move the call to setSize down to the bottom of the constructor:

setSize or pack create the peer and signal the layout manager to layout its components. You want to call one of them after you add you components to the content pane. Otherwise you will have to validate the layout.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!