Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java swing setMaximumSize not working [duplicate]

Tags:

java

swing

jframe

Possible Duplicate:
setMaximumSize not working in java

I've having trouble with my JFrame subclass. I need to set a Maximum height.

But setMaximumSize does not work. It seems that's a bug in java (setMinimumSize works). How could prevent a JFrame from getting higher than a given height ?

like image 341
Matthieu Riegler Avatar asked Apr 14 '12 22:04

Matthieu Riegler


2 Answers

In my experience, setMinimumSize and setMaximumSize are not reliable - they may work in some situations, but often not in others

The best solution is to use a ComponentListener, implement componentResized, and enforce the min / max size that way

like image 86
ControlAltDel Avatar answered Sep 16 '22 18:09

ControlAltDel


Use this instead/as well:

setPreferredSize(new Dimension(width, height));

In my experience setPreferredSize(Dimension) takes preference and always works.

I usually use all of them anyway: setMinimumSize(), setMaximumSize(), setPreferredSize() and then setSize() as well

like image 32
Ozzy Avatar answered Sep 19 '22 18:09

Ozzy