wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes GridBag Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBag Help" Watch "GridBag Help" New topic
Author

GridBag Help

bapi dhar
Ranch Hand

Joined: Mar 02, 2001
Posts: 32
Dear Friend

Having difficulty in GridBagLayout.
Please give some small examples to understand the GridBagconstraints and how to use them in different situations.
Thankyou u very much.
bapi

------------------
bapi dhar
Ranch Hand

Joined: Mar 02, 2001
Posts: 32
friends
when i would to put 2 objects
1) next to each other side by side like one one
2) one by one like this
one
one
how do u do it
thanx
bapi
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Bapi,
Here is a link about using GridBagLayout: http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html
However, if all you want to do is arrange controls as you describe here:

1) next to each other side by side like one one
2) one by one like this
one
one

GridBagLayout is more complex than necessary. In that case, just use GridLayout like this:

This code puts the buttons side-by-side like: one two.
To make them like:
one
two
just change the line from
setLayout(new GridLayout(1,2));
to
setLayout(new GridLayout(2,1));
Hope this helps.
Stephanie
bapi dhar
Ranch Hand

Joined: Mar 02, 2001
Posts: 32
dear friends

i thank u for your help.

bapi.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: GridBag Help