• Post Reply Bookmark Topic Watch Topic
  • New Topic

getPreferredSize() of a Dialog Window  RSS feed

 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to open a Dialog Window in a "framed" application, with its preferred size (depending on the width of the message).
Also I wanted it centered in the frame.
I thought I could all do this in the constructor of the Dialog Window. I took me about half an hour to finally realize that
getPreferredSize() return 0, 0!!! Either from within the constructor of the my Dialog Window, or from the frame that instantiated it!
Why did getPreferredSize() returned 0, 0?
Is there a way to figure out the best size of a window before opening it?
Thanks!
 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pack() will set the container to the preferred size. You will still have to set your dialog window visible after the pack().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!