How to layout textfields and keep size at 1 character height

J

Jim

I'm trying to layout a series pairs of labels (JLabel) and text fields
(JTextfield) for a form.

Is there an easy way of doing this and constraining the height of the
textfield to be 1 character height?
Ideally, I could just plunk down a text field and have it be the right
height (with a border would be nice) regardless of its container and layout
style.

I've tried a 2-column grid with labels on the left and textfields on the
right and the textfield gets resized
whenever the grid is resized. Trying two side-by-side panels with vertical
box layouts doesn't work either.

Putting the textfield on its own JPanel keeps the textfield a constant size
but this seems like overkill.

Is subclassing a JTextfield (or a JPanel with JTextfield) so I don't have
set each one up individually a solution?

I'm using JBuilder Foundation IDE.

Thanks for your suggestions.

Jim Cant
 
A

Andrew Thompson

I'm trying to layout a series pairs of labels (JLabel) and text fields
(JTextfield) for a form.

Is there an easy way of doing this and constraining the height of the
textfield to be 1 character height? ....
Putting the textfield on its own JPanel keeps the textfield a constant size
but this seems like overkill.

??? What's dead?

BorderLayout, JPanel with GridLayout in WEST
for JLabels, JPanel with GridLayout in EAST
for JTextField.

The JLabels get as much space as they need,
the TextFields get the rest.

If you do not like the fact that this design
_too_ can increase greater then 1 char height,
wack the entire assenblage in the NORTH area
of a second BorderLayout.

...If you are especially against nested Layouts,
you might check out the JGoodies FormLayout,
which as I understand is specialized for just
this type of situation. No JPanels need 'die'. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top