The moose likes Swing / AWT / SWT and the fly likes GridBagLayout with fixed columns width Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout with fixed columns width" Watch "GridBagLayout with fixed columns width" New topic
Author

GridBagLayout with fixed columns width

Adriano Bellavita
Ranch Hand

Joined: Mar 11, 2010
Posts: 37
Hi all,

I have implemented a simple Jfame, by using GridBagLayout

This is the code:



So I have 4 simple labels in my frame, on the same rows.

My problem is that I want all labels with fixed width: but the second label (containing "a" String) is smaller than the third one (longer string).

How can I fix the columns width, in the way that all my labels will have same width?

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> How can I fix the columns width, in the way that all my labels will have same width?

use a GridLayout
Adriano Bellavita
Ranch Hand

Joined: Mar 11, 2010
Posts: 37
My problem is that my frame is a little bit more complex.

I have a lot of components in my main Frame, so I can't simply change the main layout.

Is there a way to obtain the same result by using gridBagLayout?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

You can nest layouts.


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Find out about Cay Horstmann’s GBC class. It makes grid bag much easier to use.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Is there a way to obtain the same result by using gridBagLayout?

you would need to give all labels the same preferredSize
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout with fixed columns width