In Java , i am Searching for that for a while , but can't understand that What is the Difference Between setPreferredSize()
and setMaximumSize()
,
Can anyone explain that easily?

- 109,525
- 20
- 134
- 319

- 634
- 2
- 7
- 25
-
1i guess, you never used it!!3 – Rajendra arora Feb 08 '14 at 10:10
-
3well, they are sizing hints, specifying the preferred vs. the maximum size that a components thinks correct for itself. Anyway, [don't use setXXSize, ever](http://stackoverflow.com/a/7229519/203657) – kleopatra Feb 08 '14 at 10:10
-
1May be [this](http://stackoverflow.com/questions/1783793/java-difference-between-the-setpreferredsize-and-setsize-methods-in-compone) – ravibagul91 Feb 08 '14 at 11:36
1 Answers
Preferred size is the one that layout managers try to honor if possible. If this does result in a layout that does not comply to the rules of each layout manager however, the element may be resized. Minimum and maxmum size specify to what extent the element can be scaled by layout managers.
If you're not using any layout managers, minimum, maximum and preferred size don't do anything.
As @kleopatra mentioned in the comments however, you should avoid setting any of the three hints. Just let the layout manager determine the best size on its own. If that really leads to ugly results, change the layout manager or layout manager settings/constraints, write your own layout manager or work without one. Otherwise, differnet DPI settings, display resolutions or unexpected window sizes may completely break your layout.

- 5,875
- 1
- 20
- 40