Set maximum size on GroupLayout

60 Views Asked by At

I have a button that I want to be resizable dependent on the JPanel size. But I want to change its maximum height to bigger than its default size but not infinite. How can i accomplish this?

                                .addComponent(btnNewButton_7, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                                .addGap(177)) -- Horizontal group      



                                            .addGap(21)
                        .addComponent(btnNewButton_7, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
                        .addGap(25) -- Vertical Group
1

There are 1 best solutions below

0
Nicolas Calafiore On

To those who may find this on google in the future

On whichever axis you prefer to limit, change the last word (on mine its GroupLayout.PREFERRED_SIZE but if its set to re-sizable it should be GroupLayout.DEFAULT_SIZE) to whichever number you wish to limit it to.

I.E

.addComponent(btnNewButton_7, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)

to

.addComponent(btnNewButton_7, GroupLayout.DEFAULT_SIZE, 89, 100)

The above change makes it grow 11 more to a maximum of 100.