Set only maximum height for a panel (without using setMaximumSize) with GroupLayout
gridbaglayout, grouplayout, java, swing
Solution
If you want to limit only one dimension then just do not limit the other:
component.setMaximumSize( new Dimension(
Integer.MAX_VALUE,
requiredMaxHeight
) );
Problem
I looked around at all the other answers, but they all recommend to use `GroupLayout`, `BoxLayout`, or to wrap the panel that's using GridBagLayout with another panel that uses one of the layouts mentioned above. I'm currently using GridBagLayout, and I'm wondering if there's a way to set the maximum height of a panel. I don't want a limit on width, only height, so `setMaximumSize(Dimension)` won't work. Does GridBagLayout support this in any way? Sorry if my question doesn't contain any code, the only attempt I could possibly find is `setMaximumSize(Dimension)`, or wrapping it in another panel (which I'm hoping to avoid)