my dog learned polymorphism
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

Win a copy of The Software Craftsman this week in the Agile forum!
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: 2282
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: 41640
Also Google for MigLayout. I have never tried it, but those who have say it's very good.
Have you tried LearnNowOnline?
subject: Grid Layout Problems