July 13, 2004

Why GridBagLayout must die

If you have ever tried to understand how the GridBagLayout works, I am sure this will strike a chord.

 

Posted by cedric at July 13, 2004 06:14 AM
Comments

This is so funny, I use gridbag every week and I still can't put my widgets at the right place on the first try....

Posted by: Simon at July 13, 2004 06:55 AM

Really great!

And worst of all... there existed better layout mechanisms ages before (think NeXTStep).

Posted by: Heiko at July 13, 2004 07:08 AM

Basically the layout manager in NeXTStep, now used in Interface Builder on Mac OS X, is Springs-n-Struts except that it is much easier to use because every spring and strut isn't an object and are directly on the components. Additionally, you almost never use it programmatically, only in the building tool.

Posted by: Sam Pullara at July 13, 2004 01:20 PM

I have switched to using forms from jgoodies for 99% of my layout needs.

It has been open sourced by SUN, and is a joy to use.

It's the best layout since SlicedBreadLayout. No Swing/SWT programmer should be without it.

Posted by: Zohar at July 13, 2004 03:31 PM

Trial & Error, that's what I can remember from the GridBagLayout.
But could we also kill the java.awt.LayoutManager2 interface?
Just for being named in a dumb way?

But GridBagLayout anyday over a null layout or a FlowLayout ;-).

Posted by: Barre Dijkstra at July 14, 2004 12:14 AM

If Sun only fixed this annoying BUG, I would happily use GridBagLayout happy after:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4238932

Only one example why Swing (AWT) is screwed up for no reason.

Posted by: svenmeier at July 14, 2004 02:10 AM

Too funny !
But GridBagLayout is worse than this in fact!

Thank for the link :)

Posted by: patrick at July 15, 2004 12:51 PM

I actually wrote a little prog to generate gridbaglayout more interactively. It is on
http://easygridbag.sourceforge.net

It is not intuitive to work with GridBagLayout but powerful enough for all your needs, that is why I would not spit on it as much as you guys.

JGoodies is nice but is much more than just a Layout.

Posted by: qwerty at July 16, 2004 02:33 AM

I love gridBagLayout! once you get the hang of it you can quickly layout things exactly where you want them. this is as complex as my layouts can get it may look a bit intimmidating at first but it's quick to write and easy to maintain -

setLayout(new GridBagLayout());
int COL_BTN = 1;
int COL_LBL = 2;
int COL_TXT = 3;

add(getBtnStringBeforeToken(), new GridBagConstraints(COL_BTN,1,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(4,0,0,4), 0,0));
add(getBtnMaximumLength(), new GridBagConstraints(COL_BTN,2,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(4,0,0,4), 0,0));
add(getBtnDelimiter(), new GridBagConstraints(COL_BTN,3,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(4,0,0,4), 0,0));
add(getBtnStringAfterItem(), new GridBagConstraints(COL_BTN,4,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(4,0,0,4), 0,0));

add(new JLabel("String before leading token:"), new GridBagConstraints(COL_LBL,1,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 0,0));
add(new JLabel("Maximum length of leading token:"), new GridBagConstraints(COL_LBL,2,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 20,0));
add(new JLabel("Delimiter:"), new GridBagConstraints(COL_LBL,3,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 0,0));
add(new JLabel("String after list item:"), new GridBagConstraints(COL_LBL,4,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 0,0));
add(new JLabel("Minimum required items:"), new GridBagConstraints(COL_LBL,5,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 0,0));
add(new JLabel("Selection field:"), new GridBagConstraints(COL_LBL,6,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 0,0));

add(getTxtStringBeforeToken(), new GridBagConstraints(COL_TXT,1,1,1,1,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 70,0));
add(getMaximumLengthSpinner(), new GridBagConstraints(COL_TXT,2,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 10,0));
add(getTxtDelimiter(), new GridBagConstraints(COL_TXT,3,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 40,0));
add(getTxtStringAfterItem(), new GridBagConstraints(COL_TXT,4,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 70,0));
add(getMinimumItemsSpinnner(), new GridBagConstraints(COL_TXT,5,1,1,0,0,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 10,0));
add(getPnlPositionSelection(), new GridBagConstraints(COL_TXT,6,1,1,0,1,GridBagConstraints.NORTHWEST,GridBagConstraints.NONE, new Insets(VERTICAL_LINE_SPACING,0,0,0), 0,0));

we're actually moving to swt hell right now and i can't find a normal layout.. swt gridBag really sucks

Posted by: plasticfloor at March 13, 2007 04:33 AM
Post a comment






Remember personal info?