• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GridbagConstraints

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://pandonia.canberra.edu.au/java/xadvisor/gridbag/gridbag.html 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
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer to this discussion.
regds
maha anna
[This message has been edited by maha anna (edited March 20, 2000).]
 
Jerson Chua
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much maha anna.
reply
    Bookmark Topic Watch Topic
  • New Topic