File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Grid Layout Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Grid Layout Problems" Watch "Grid Layout Problems" New topic

Grid Layout Problems

Brian Batson

Joined: Jun 15, 2011
Posts: 11

I am using a GridLayout to display a variety of information. It's working just fine but I really wish I could set the width of the columns (like a JTable) for the columns within the GridLayout.

See the attached screen shot for a sample (assume the JLabels are different from the first and second columns).

As you can see, the GridLayout evenly spaces the columns, although I would prefer for the columns holding the JLabels to be much smaller than the size for the columns holding the JTextFields.

Any guidance that you can provide is very much appreciated.

[Thumbnail for grid_layout_sample.jpg]

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2447
A GridLayout won't do what you want.

Read up on Layout Managers. A SpringLayout or GridBagLayout would be your best bet.
Brian Batson

Joined: Jun 15, 2011
Posts: 11
Awesome, thanks, Rob. Somehow I missed SpringLayout in my initial cursory review of available layouts. The SpringForm mentioned about 3/4 down the following webpage addresses my needs completely:

Thanks, again.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46334
Also Google for MigLayout. I have never tried it, but those who have say it's very good.
I agree. Here's the link:
subject: Grid Layout Problems
It's not a secret anymore!