Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

GridBagConstraints: weightx and weighty

 
Ramsin Khoshaba
Ranch Hand
Posts: 65
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I can't figure out what weightx and weighty do. I have looked at the API doc, but no luck.
Can you explain what they are for, reword the doc?

Thanks.
 
Rob Camick
Ranch Hand
Posts: 2703
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the tutorial on How to Use GridBagLayout will help. It explains all of the contraints and has working examples.
 
Stephan van Hulst
Bartender
Posts: 6589
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a couple of components laid out in a panel, and you stretch the panel, the extra space needs to go somewhere. The weightx property determines how horizontal space is distributed over the cells, and weighty determines how vertical space is distributed.

If all cells have the same positive weight, the extra space is distributed evenly. If a cell has a weight that's twice as much as the weight of other cells, it will get two pixels of extra space for every pixel that the other cells get.

Let's say you have a label, a text area and a button, positioned vertically in that order. If you want the cell of the text area to soak up all the extra space if the container stretches, you can set the weighty of that cell to any positive value, and set the weighty of all the other cells to 0.
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!