I have two JLabels, one JTextField and one JTextArea.
I want the JLabels and the JTextField to be limited to one line in
depth, but the JText Area to expand the rest of the space.
How would i go about this?
Thanks
Dave Glasser - 07 Jan 2004 03:59 GMT
arun_hallan@hotmail.com (Arun Hallan) wrote on 6 Jan 2004 14:03:47
-0800 in comp.lang.java.gui:
>I have two JLabels, one JTextField and one JTextArea.
>
>I want the JLabels and the JTextField to be limited to one line in
>depth, but the JText Area to expand the rest of the space.
>
>How would i go about this?
A GridBagLayout should do the trick.

Signature
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.
http://qform.sourceforge.net
Andrew Thompson - 07 Jan 2004 05:51 GMT
| I have two JLabels, one JTextField and one JTextArea.
|
[quoted text clipped - 4 lines]
|
| Thanks
You need the..
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html
however..
setLayout(new BorderLayout());
Panel pNorth = new Panel( new GridLayout(0,1) );
pNorth.add( label1 );
pNorth.add( textField1 );
pNorth.add( label2 );
add( pNorth, BorderLayout.NORTH );
add( texArea, BorderLayoutSOUTH );
--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Arun Hallan - 07 Jan 2004 17:01 GMT
> | I have two JLabels, one JTextField and one JTextArea.
> |
[quoted text clipped - 20 lines]
>
> add( texArea, BorderLayoutSOUTH );
Thanks...
The top and bottom panels ive made north and south and then included
another panel in the middle as center which contains the jtextarea.
This seems like such a complecated way to do a simple thing, thought
there wud be a function to limit the jtextfield changing size.
Thanks
Andrew Thompson - 08 Jan 2004 05:48 GMT
"Arun Hallan" <arun_hallan@hotmail.com> wrote in message
..
| The top and bottom panels ive made north and south and then included
| another panel in the middle as center which contains the jtextarea.
|
| This seems like such a complecated way to do a simple thing, thought
| there wud be a function to limit the jtextfield changing size.
It's not really _that_ complicated.
Part of the reason, I think, it is not as simple as it could be
is that java is generally not well suited to 'exact positioning'
as you might be used to. There is a good reason.
Fonts will not be exactly the same size on different
systems, or their default button style may be slightly
bigger or smaller than the OS you are using, et cetera..
For this reason you need to learn to leave the
layout of the GUI to an appropriate Layout
Manager.
It sounds like you have now got the basic,
idea give it a while while and this will seem
quite natural.
--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Karsten Lentzsch - 11 Jan 2004 12:21 GMT
> I have two JLabels, one JTextField and one JTextArea.
>
> I want the JLabels and the JTextField to be limited to one line in
> depth, but the JText Area to expand the rest of the space.
>
> How would i go about this?
I recommend the following to ensure a good readability,
or mor generally, legibility of your form design:
Create a layout with two rows that get the same height.
Center the label and the text field in the first row;
center the second label in the second row.
Append a glue at the bottom and let the text area
span the second row and the glue. This way you have
a chance to get a consistent alignment of perceived
component bounds and more important: font baselines.
I provide a demo that compares three approaches on
how to implement your layout task with my FormLayout.
See the "Custom Rows" and "Custom Areas" examples in
the JGoodies Forms Demo version 1.0.3 pre (refs below).
Anyway, HIGLayout could do the same, TableLayout and
GridBagLayout only to a lesser extent.
You can find the source code for the Forms Demo panels
in the tutorial sources of the JGoodies Forms distribution.
Even if the layout manager positions the components well,
the acuracy of the finished screen design depends on the
look&feel implementation; or more specific: on the insets
of labels and different widget types of the look&feel.
The JGoodies Looks ship with a precise Windows emulation
and the precise Plastic l&f family - all open and for free.
I've recently fine tuned more component types to align
font baselines precisely: spinner, password field, text area,
editor pane. The ships with the JGoodies Looks 1.2 preview.
I'm aware of only a single other l&f that catches up:
the Mac OS X Aqua L&f implementation in 1.4.2 preview (not 1.4.1).
Hope this helps,
Karsten Lentzsch
References:
http://www.jgoodies.com/download/demos/forms/formsdemo.jnlp
http://www.jgoodies.com/download/demos/forms/formsdemo-1_0_3-20040110-win.exe
http://www.jgoodies.com/download/demos/forms/formsdemo-1_0_3-20040110-mac.zip
http://www.jgoodies.com/download/demos/looks/looksdemo.jnlp
http://www.jgoodies.com/download/demos/looks/looksdemo-1_2_0-20040110-win.exe
http://www.jgoodies.com/download/demos/looks/looksdemo-1_2_0-20040110-mac.zip