To define minimal size successfully, I have to do the following:
// setting minimal width AND height
Dimension min = new Dimension(100, 100);
comp.setMinimumSize(min);
comp.setPreferredSize(min);
comp.setSize(min);
When I left one line out it doesn’t work, which is strange, but it’s not the point.
What do I do to limit just one of two dimensions (width or height) and let the component and/or the layout manager decide automatically about the unspecified dimension?
When I use a very small value for that dimension which I don’t want to limit, many components are displayed wrong (i.e. too small).
By default (i.e. if
setMinimumSizehas not been called on the component)getMinimumSizedelegates to the component’s layout manager, so you can try to redefine thegetMinimumSizemethod as follows:If you do this, remember that you should not call
setMinimumSizeon the component.