Gridbag Layout

I am try to understand this layout manager. But can not create a grid with 3 columns and any number of rows. This first row is fine, but all rows after that do not show that first column. Can anyone tell me why the first component in my rows do not appear ?

/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Create and set up the window.JFrame frame = new JFrame("GridBag Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.JComponent newContentPane = new Main(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); frame.setJMenuBar(menuBar);

It's not worth learning it, and even if you understand it during one project, you are going to forget the lousy details when you start another...

I would not agree with this at all. I can't live without this layout (and yes I have tried jgoodies). It is just so powerful. The learning curve is steep, but very worth it in my opinion.

And what happens if you get put on a project that does use it? I guess you could refactor it all to use jgoodies but that would require understanding the gridbag layout code in the first place in order to translate it properly ...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus

Biliang Zhou
Ranch Hand

Joined: Jun 28, 2006
Posts: 43

posted Sep 11, 2006 16:23:00

0

I would not agree with this at all. I can't live without this layout (and yes I have tried jgoodies). It is just so powerful. The learning curve is steep, but very worth it in my opinion.

Sure, GridBag is powerful, but it comes with the price tag of a sharp learning curve. It can do some really tricky tasks, which can be mission impossible for other layouts. But how often do beginners and mid-level swing programmers use GridBag layout in a complex way? I see the initiator of this thread as one who is learning the layout managers. So I suggest spend less time on GridBag.

And what happens if you get put on a project that does use it? I guess you could refactor it all to use jgoodies but that would require understanding the gridbag layout code in the first place in order to translate it properly ...

That is not exactly true... If you need to refactor a GUI you can just run the application, do a screen capture, and start from the screen capture to "interpret" it. How long does it take to interpret a GridBag Layout into a JGoodies FormLayout? No more than 10 minutes if you have a screen capture to look at!

Jared Cope
Ranch Hand

Joined: Aug 18, 2004
Posts: 243

posted Sep 12, 2006 03:02:00

0

Hi,

Originally posted by Biliang Zhou:

If you need to refactor a GUI you can just run the application, do a screen capture, and start from the screen capture to "interpret" it.

But what happens when you resize the screen in different ways? Components move around and get different sizes. How many screen captures do you need then to see all the required behaviour? If you know how to read gridbag layout contraints you will just know what will happen in all situations.

But at the end of the day, they are all just tools to get the job done.

Cheers, Jared.

Biliang Zhou
Ranch Hand

Joined: Jun 28, 2006
Posts: 43

posted Sep 12, 2006 08:34:00

0

But at the end of the day, they are all just tools to get the job done.

That's true, that's true. Can't agree more. Hope someday these tools can be more intelligent to make life a little bit easier for us...