Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2003

Tip: Looking for answers? Try searching our database.

GridBagLayout weightx question (not a FAQ)

Thread view: 
Laird Nelson - 04 Nov 2003 14:28 GMT
First off, apologies for using the Google news interface; I hope this
is sent in plain text only with sane wrapping.  Once I get home I'll
switch back to Thunderbird.

My question concerns weightx.  In general, I understand how weightx
and weighty work, and I've been using GridBagLayout for nearly all my
GUI layouts for several years.  But I've stumbled across a situation
where I can't figure out what's happening.

I have a simple properties-type panel that I'm putting together.
There are notionally four colums: the label column, the widget column,
which always has a gridwidth of three, and then two extra columns
which are only "filled" by command buttons in the bottom row.  An
ASCII excerpt follows:

+-------------------------------+
|        +--------------------+ |
| label: |         widget     | |
|        +--------------------+ |
|              +------+ +------+|
|              | but1 | | but2 ||
|              +------+ +------+|
+-------------------------------+
{ col0  }{col1}{ col2 } { col3 }

Components in column 1 (the widgets) have a weightx of 1F, which of
course grants them all available extra space.  So when you resize the
panel, text boxes expand, for example, but labels do not.

The command button row is what's giving me problems.  I'd like, if
possible, to not specify *anything* for columns 0 and 1, and to just
start with column 2.  But I don't want column 2 *or* column 3 to have
weightx values > 0 (i.e. I want their size to remain fixed.

The only way I've come up with to solve this problem is to put a super
lightweight component (like Box.createGlue()) in column 0 with a
gridwidth of 2 and a weightx of 1.  This offends my sensibilities, as
I don't really want *any* component in columns 0 *or* 1 in the bottom
row.

Is there any "pure" GridBagLayout way to accomplish this?

Thanks,
Laird
Stephan Friedrichs - 04 Nov 2003 15:22 GMT
> [...]
>
[quoted text clipped - 17 lines]
>
> Is there any "pure" GridBagLayout way to accomplish this?

I suppose it is enough to put the left button in columns 0 to 2
with weightx on a high value, fill on NONE and anchor on EAST, so
that it takes all the space left of it without using it up. At
least that worked fine in my projects...

> Thanks,
> Laird

Hope this helps - Stephan

Signature

Spam protection: If an email response to this posting
is necessary, please respond to:

            SFriedrichs [at] t-online [dot] de

--

http://home.t-online.de/home/sfriedrichs/

   JAddressBook: 1.1

Laird Nelson - 04 Nov 2003 19:32 GMT
> I suppose it is enough to put the left button in columns 0 to 2
> with weightx on a high value, fill on NONE and anchor on EAST, so
> that it takes all the space left of it without using it up. At
> least that worked fine in my projects...

No, unfortunately that doesn't work, but it's almost right.

The only way I've managed to make this work without adding a dummy
component is to put my first button in column *1*--not 0--with a
weightx of 1, so that every component in that column has the same
weightx value.  Then I made its gridwidth 2, and its anchor to the
east, so that it fills those two column spots.

If I put it in column 0 with a gridwidth of 2 and a weightx of 1, then
space is not correctly allocated for some reason--the button, instead
of pushing over to the right edge of column 3, takes up space midway
between columns 2 and 3.  Whatever.  I like GridBagLayout, I really
do, but every time I use it I have to hack something, and I end up
just feeling like an idiot, and it's all I can do to tear myself away
from trying to figure out *why* it works and just let it work with the
hack installed.

Frustrated,
Laird
A. Bolmarcich - 04 Nov 2003 16:21 GMT
> First off, apologies for using the Google news interface; I hope this
> is sent in plain text only with sane wrapping.  Once I get home I'll
[quoted text clipped - 37 lines]
>
> Is there any "pure" GridBagLayout way to accomplish this?

Assign to the public instance variable double[] columnWeights of the
GridBagLayout object the value {0.0, 1.0, 0.0, 0.0}.  If you do this,
you can also let the weightx constraint of the "widget" be 0.0.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.