Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set only maximum height for a panel (without using setMaximumSize) with GroupLayout

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)

like image 258
Vince Avatar asked May 20 '14 05:05

Vince


1 Answers

If you want to limit only one dimension then just do not limit the other:

    component.setMaximumSize( new Dimension(
            Integer.MAX_VALUE,
            requiredMaxHeight
    ) );
like image 114
Oleg Estekhin Avatar answered Nov 15 '22 11:11

Oleg Estekhin