Author Topic:   GridbagConstraints
Jerson Chua
ranch hand
posted March 19, 2000 10:36 PM             
and the one in the Java Tutorial
I've already read the article above but GridbagContraints still seemed to be unclear to me. Can anyone clarify some of my doubts

How does weightx and weighy y work?
Also, i've read some previous posting which said that if fill=GridbagContraints.BOTH, the ipadx and ipady are not irrelevant. But I've tried it and it seemed to me that ipadx and ipady do not affect the appearance of the component if fill=GridbagContraints.BOTH.

Thanx...

Jerson

Tony Alicea
sheriff
posted March 20, 2000 06:31 AM             
Although I don?t have my references with me (I?m on the road again), I remember that these weighs are relative to the total weight of the column or row.

For example, if there are two components in a row and one has weigh 5 and the other 10, then the total is 15 so the first one occupies one third of the space and the other one, the other two thirds.

Of course, the exact same result could have been obtained if instead of 5 an 10, the numbers would have been 1 and 2; or 100 and 200... not forgetting that the numbers are of type double,

maha anna
bartender
posted March 20, 2000 07:54 AM             
Please refer to this discussion.
regds
maha anna

[This message has been edited by maha anna (edited March 20, 2000).]

Jerson Chua
ranch hand
posted March 20, 2000 05:48 PM             
Thanx Tony and maha anna
Followup question.

Does weightx and weighty affect the size of the component? Because actually what's resizing is the cell and not the component. The size of the component will only be affected if the fill is not NONE. So my question is it right to say that weightx and weighty affects the size of the component.


[This message has been edited by Jerson Chua (edited March 20, 2000).]

maha anna
bartender
posted March 21, 2000 02:42 AM             
Jerson,
The weightx,weighty concept is , how to spread the extra space got, when the container is resized, for all the component cells either horizantally or vertically, according to weightx/weighty values. So as Tony said ,each component cell will get its share (itsOwnShare/totalSharesOfallComponents in the row/col) according to the weight(x/y) it has got in its GridBagConstraints when the component was added to the container.

So what you said is correct in this regard. The individual cell gets resized ,when the container is resized according to their weightx/y values. Whether the component inside it uses the full cell ,depends on the GridBagConstraints.fill value. If a particular component's GrifBagConstraints.fill value was NONE when it was added to the container,then you can see the component's size remains same at all the time , but the containing cell gets resized.

So the final verdict is ,the fill attribute says whether to stretch or not/ if stretched in which way only. How much the component gets resized depends on its own weithtx/weighty value. So we can say that
weightx/weighty affects the size of the component

regds
maha anna

[This message has been edited by maha anna (edited March 21, 2000).]

Jerson Chua
ranch hand
posted March 21, 2000 06:37 PM             
In this case, I can also conclude that gridwidth and gridheight affects the size of the component since the gridwidth and gridheight define how much cell a grid span. (same case with weightx/weighty) So if i were asked about what fields in GridbagConstraints affect the size of component. I can say gridwidth/gridheight, weightx/weighty, ipadx/ipady and fill affect the size of a component. Please verify.

Thanks for your patience.

Jerson

maha anna
bartender
posted March 23, 2000 12:07 PM             
yes. You are correct.

Also one more point.
All components in a row will have same height.
Each row can have diff heights.
Each col can have diff widths.
All components in a col will have same width.
This uniform height for a row / uniform width for a col is determined by the following rule.

The height of a component in a row is the maximum height of all the components in row by looking at their preferredSize().height + 2 times ipady.

Simillarly,the width of a component in a col is the maximum width of all the components in col by looking at their preferredSize().width + 2 times ipadx.

Because at present the uniform height of a row can be a particular value. But we can't gurantee that it will remain same at all times right? When one more component is added with larger preferredSize().height/width then all the components size (height/width) are changed to have this new width/height. When a new component is added with smaller preferred width/height , all the other component's size do not change. But this new comp's width/height will set to the already existing uniform height/width.

So we can say a size of a component (width/height) is also affected by the preferredSize().width /preferredSize.height of other components in the SAME row/col.(though it is not one of fields of GridBagConstraints class)
regds
maha anna

[This message has been edited by maha anna (edited March 24, 2000).]

Jerson Chua
ranch hand
posted March 23, 2000 05:39 PM             
Thank you very much maha anna.

|