• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GridBagLayout

 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is GridBagLayout behavior on resizing i.e will it honor preferred size or not.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GridBagLayout has weightx and weighty parameters for each component that determine how much each component can grow relative to the resizing of the window. If you leave these unset (0) then the components will NOT grow with the window. If you set them, then the relative value of the weight for the component is compared to the relative weights of the other components on the screen and this determines how much the growth will be. When making the window smaller, the shrinkage is of course also proportional.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends. Normally, resizing the container will not resize the components within a GridBagLayout. However, if you use anchors or fill, the component will resize.
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Cindy Glass:
GridBagLayout has weightx and weighty parameters for each component that determine how much each component can grow relative to the resizing of the window.

Actually, if I'm not mistaken, these don't effect the size of the component but rather the size of the cell that the component is in. So a button will not change size using weightx or weighty but the cell the button is in will grow or shrink based on their settings. The button will remain at its preferred size.

------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
GridBagLayout by default will honor the prefered size of the components.
The weightx and weighty are proportions that are applied to the cell.For example, if you have 2 columns (cells) and you want the first column to occupy more area compared to second column, you may have the weightx property of the first cell as 60 and the other cell as 40.These properties have nothing to do with the prefered size of the components in the cell.
What can affect the prefered size is the GridBagConstraints.fill.If you initialize this parameter to BOTH,HORIZONTAL, or VERTICAL, then the prefered size of the component will not be honored.
However, note that by default this parameter is set to GridBagConstraints.NONE, hence the components are displayed in the smallest possible size.
Hope this helps,
Sandeep
SCJP2,OCSD(Oracle JDeveloper),OCED(Oracle Internet Platform)
[This message has been edited by Desai Sandeep (edited August 03, 2001).]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Desai Sandeep:
What can affect the prefered size is the GridBagConstraints.fill.If you initialize this parameter to BOTH,HORIZONTAL, or VERTICAL, then the prefered size of the component will not be honored.Sandeep
As I mentioned above, anchor may also cause the preferred size to be ignored.
 
Ashish Jaiman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.jchq.net/tutorial/08_01Tut.htm
this would provide u with detail and help u undersatnd it better
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,

Originally posted by Thomas Paul:
As I mentioned above, anchor may also cause the preferred size to be ignored.

If I am not mistaken, it is only FILL that can affect the preferred size of the components.The ANCHOR would just position the components in the cell- CENTER is the default; others being NORTH, NORTHWEST, NORTHEAST, SOUTH, SOUTHWEST, SOUTHEAST, WEST and EAST.Also, when you specify FILL, ANCHOR constraints are ignored.
Hope this helps,
Sandeep
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Desai Sandeep:
If I am not mistaken, it is only FILL that can affect the preferred size of the components.The ANCHOR would just position the components in the cell- CENTER is the default; others being NORTH, NORTHWEST, NORTHEAST, SOUTH, SOUTHWEST, SOUTHEAST, WEST and EAST.Also, when you specify FILL, ANCHOR constraints are ignored.
You are correct. I had assumed that you could anchor on more than one corner, but you can't. You would use a combination of fill and anchor in order, for example, to stretch between NW and SW. So the correct answer is that ONLY fill will change the size of a component in a GridBagLayout.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic