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!
posted 16 years ago
pack() will set the container to the preferred size. You will still have to set your dialog window visible after the pack().