I was also confused by the way GroupLayout.DEFAULT_SIZE and GroupLayout.PREFERRED_SIZE are used in GroupLayout.SequentialGroup.addComponent(Component c, int min, int pref, int max) , even after linking to the GroupLayout section in Java tutorials and the java.net article under titled Introducing GroupLayout, Part 1 .
Diving in JDK 1.6.0_27 GroupLayout.javasource I found the answers in the ComponentSpring class. From this, I was able to work out these rules:
If a minimum size is required:
- and the provided
min value is non-negative, this value is returned. - else if it is
PREFERRED_SIZE , we follow the rules for the preferred size. - otherwise, the minimum component size is returned.
If preferred size is required:
- and the provided
pref value is non-negative, this value is returned. - else, if it is
DEFAULT_SIZE or PREFERRED_SIZE , return the preferred component size.
If maximum size is required:
- and the provided
max value is non-negative, this value is returned. - else if it is
PREFERRED_SIZE , we follow the rules for the preferred size. - otherwise, the maximum size of the component is returned.
As already noted, trashgod determines negative. Any other negative value for min, pref, and max other than DEFAULT_SIZE or PREFERRED_SIZE is an error and raises assertions.
The interaction between the sizes of SequentialGroup.addComponent min, pref, and max did not immediately appear to me from the tutorial. Now I know why PREFERRED_SIZE,DEFAULT_SIZE,PREFERRED_SIZE fixed, why it does not matter if the middle argument is DEFAULT_SIZE or PREFERRED_SIZE and how NetBeans fixed size values โโsuch as DEFAULT_SIZE,300,Short.MAX_VALUE .
jla
source share