Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GridBagLayout with fixed columns width

 
Adriano Bellavita
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can nest layouts.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find out about Cay Horstmann’s GBC class. It makes grid bag much easier to use.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic