This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Using GridBagLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using GridBagLayout" Watch "Using GridBagLayout" New topic

Using GridBagLayout

Gonella Jayprakash

Joined: Mar 22, 2007
Posts: 5
I implement a JFrame and the layout for the JFrame as GridBagLayout. When I add a component to the JFrame and gridx=0 and gridy=0, it is being placed at the centre of the JFrame. Now I move the component to customize but I am unable to. Even on changing the gridx and gridy, I am unable to move the component.

I am also unable to pre-define the GridBagLayout grid by defining the columnwidths and rowheights for the GridBagLayout. This way I think by altering the gridx and gridy, I can move the component in the JFrame.

Any pointers as to what I am doing wrong?

Thanks & Regards,
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you need to set weightx and/or weighty

from [somewhere]

"By default, weightx and weighty have the value 0. When all component's
weightx and weighty values are 0, no components get any extra space. In
addition, all components are positioned in the GridBagLayout relative to the
center of their container"

from the apidocs
"If all the weights are zero, all the extra space appears between the grids of
the cell and the left and right edges."
"If all the weights are zero, all the extra space appears between the grids
of the cell and the top and bottom edges."
I agree. Here's the link:
subject: Using GridBagLayout
It's not a secret anymore!