>>>> If someone is interested, I'm looking to make the following:
>>>> A JTable covering the frame 100% horizontally and about 70% vertically,
[quoted text clipped - 19 lines]
> setLayout and add methods to invoke on the content pane of the JFrame
> rather than the JFrame)
As of 1.5 JFrame.add() is the same as JFrame.getContentPane().add()
the width of "70%" button is 248 and the width
> of the "30%" button is 140. Which is a 64%/36% distribution of the
> width, not 70%/30%.
Looks pretty close to me.
> If setSize(400,300) is replaced with pack(), then the width of each
> button is 59. Which is a 50%/50% distribution of the width, not
[quoted text clipped - 4 lines]
> space to the larger button and 30% of the extra space to the smaller
> button will keep the widths of the components in the 70%/30% ratio.
If the components are at their minimum sizes they will probably be the
same size.
TableLayout looks nice but it isn't part of Sun's API. I try not to use
things like that because they go out of date or are no longer supported
or whatever. If you stick to what comes with the API you can do what
the OP wanted, to a reasonable degree, and that's all you usually get
out of a layout manager any way.
The one thing I see that he is going to have a problem with is that
JTables don't appear to resize vertically.
The easiest solution is to not use a layout manager. I know that that
sends shudders through the cognoscenti but there are millions of C
programs out there that position their components that way.
knute...
Andrew Thompson - 26 Sep 2006 04:59 GMT
...
> The easiest solution is to not use a layout manager.
I was just *waiting* for someone to say that. ;-)
>...I know that that
> sends shudders through the cognoscenti but there are millions of C
> programs out there that position their components that way.
I can see how that can work in two situations..
1) If the text size, look and feel and other UI
related matters can be pinned down to the last detail.
That may be true of your typical C program, but Java
GUI's are more *often* X-plat, Multi-PLAF, used under
(potentially) different Java versions and end user
settings (screen res., font size - etc.), any of which
can destroy the rendering of (textual) components in
an 'absolutely positioned' GUI.
..if you are writing a 'run once' dev. tool, I see no
reason to worry about any the above - for most
other Java GUI projects, they become a factor.
2) If the entire content area is something you are about
to render, pixel by pixel (e.g. rotatable 3D wire-frames
or models), but that situation is not one where there is
any point to actually setting a null layout - just override
paint()/paintComponent() and go wild!
..and I ultimately think that if the project actually needs
a PutItWhereverIDropItLayout, it only takes a few lines
of code to turn (whatever) short logic that may entail,
into a LayoutManager.
(I refuse to shudder)
Andrew T.
Thomas Weidenfeller - 26 Sep 2006 08:20 GMT
> The easiest solution is to not use a layout manager. I know that that
> sends shudders through the cognoscenti but there are millions of C
> programs out there that position their components that way.
Sure. Only that they are compiled for a particular platform. And tend to
fail in interesting ways when e.g. localized, or the basic geometry of
the platform's widget set changes.
It is also rather frustrating when you once again have to deal with a
list in a window, and can't get all interesting data on the screen at
once, because the C programmer though it was a good idea to use an
non-resizable window. Particular "nice" are also tables where you often
can only get two out of three columns displayed, and need to either
scroll horizontally or shrink a table column to zero width to see the rest.
Non-resizable windows are very often a sign of a lazy or incompetent
programmer.
/Thomas

Signature
The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
A. Bolmarcich - 26 Sep 2006 16:01 GMT
[snip]
>> If setSize(400,300) is replaced with pack(), then the width of each
>> button is 59. Which is a 50%/50% distribution of the width, not
[quoted text clipped - 7 lines]
> If the components are at their minimum sizes they will probably be the
> same size.
[snip]
Because pack() was invoked, the components are at their preferred sizes,
not their minimum sizes. Using your approach, the components are the
same size, but the original poster wanted a 70%/30% distribution.
Knute Johnson - 26 Sep 2006 17:06 GMT
> The easiest solution is to not use a layout manager. I know that that
> sends shudders through the cognoscenti but there are millions of C
> programs out there that position their components that way.
>
> knute...
Honest, I wasn't really suggesting that he actually do that.
Anyway he likes the TableLayout.

Signature
Knute Johnson
email s/nospam/knute/