GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout:: a few Qs 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:: a few Qs" Watch "GridBagLayout:: a few Qs" New topic
Author

GridBagLayout:: a few Qs

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i wonder how one can control one component's display area

i'm playing with this gui and some components show much larger then their preferred or minimum sizes should predict; i even created a JButton customized class were i fixed preferred button size but with no effect

i also tried several combinations of constraints but with no effect.

I would like buttons of first row appear with their minimum or at least heir preferred size: that would make subsequent buttons to display smaller too.

How can i achieve it?

TiA

[ July 02, 2005: Message edited by: miguel lisboa ]
[ July 04, 2005: Message edited by: miguel lisboa ]

java amateur
Swati Udas
Ranch Hand

Joined: Aug 18, 2004
Posts: 121
Cannot see the sanpshot of your UI.
Can u send the relevant code instead.


SCJP 1.4 (90%)<br />SCWCD 1.4 (88%)
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
oops

thanks for pointing that out
actually i'm not at my pc, so as soon as i get there i'll post it
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i've img correctly posted now, i hope

in case you need, i'll post relevant code

TiA
Swati Udas
Ranch Hand

Joined: Aug 18, 2004
Posts: 121
Yes now I can see the snapshot..
I think u have set gridwidth=1; or some such setting for the GridBagConstraints for the Buttons..
If this is not the case..please post the code snippet..
else remove the gridwidth setting.. just dont set it to anything.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
that's exactly what i have:

i kept the HORIZONTAL fill because i want the buttons together; if i change to fill = NONE then all buttons float aside but still occupy that whole space... too big too much
Swati Udas
Ranch Hand

Joined: Aug 18, 2004
Posts: 121
U can adjust the spacing between buttons by adjusting insets..
moreover the buttons with occupy whole space because u have given anchor=lineEnd.
Try giving EAST/WEST as u want it to be.
Another tip is ..
sometimes using the same gridBagconstraints variable for multiple UI elements can mess up the UI..(as per my experience).. So I prefer to use a new GridBagConstraints variable for each button/UI element.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
control buttons width that's what i'll do as soon as i have some time ... and i guess that's all what's left
moreover the buttons with occupy whole space because u have given anchor=lineEnd.
(...)
sometimes using the same gridBagconstraints variable for multiple UI elements can mess up the UI..(as per my experience).. So I prefer to use a new GridBagConstraints variable for each button/UI element.


bingo!

thanks a lot!
[ July 05, 2005: Message edited by: miguel lisboa ]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i did it; just in case someone is interested, here's the whole code:




BTW just a curiosity: i typed twice (for both buttons subclasses)
>serialver ClassName
and got the very same serialVersionUID
[ July 05, 2005: Message edited by: miguel lisboa ]
Swati Udas
Ranch Hand

Joined: Aug 18, 2004
Posts: 121
Great!! can we see a snapshot of your final result now !!
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout:: a few Qs