I have a JDialog object that, quite simply, MUST be 200 pixels wide, regardless of its contents.
I need to be able to have the height adjusted dynamically, to always ensure that all the content is shown. How do I go about it?
- I’ve tried overriding
JDialog.getPreferredSize()method, but I can’t figure out what to add for the height value. - I’ve tried checking if the
mainJPanelisValid()andisShowing(), however, both return true as long as a part of the Panel is actually visible.
Preferred sizes are only for layout managers, they cannot restrict window sizes.
The window peer has a method for enforcing minimum size, so that works very well, but there is nothing for maximum size other than listening for resizes and resetting to desired size: