wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GridBagLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GridBagLayout" Watch "GridBagLayout" New topic
Author

GridBagLayout

ZEESHAN AZIZ
Ranch Hand

Joined: Jan 15, 2001
Posts: 162
What is GridBagLayout behavior on resizing i.e will it honor preferred size or not.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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

Joined: Apr 02, 2001
Posts: 1157
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).]


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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

Joined: May 01, 2001
Posts: 47
http://www.jchq.net/tutorial/08_01Tut.htm
this would provide u with detail and help u undersatnd it better

-AJ<br />Sun Certified Java Programmer<br />Microsoft Certified Software Developer
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
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

Joined: May 05, 2000
Posts: 13974
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout
 
Similar Threads
AWT trouble
stetching buttons
Alignment techniques for User Interface/???
Layout issue
JScrollPane and FlowLayout