How to layout textfields and keep size at 1 character height

Discussion in 'Java' started by Jim, Apr 10, 2004.

  1. Jim

    Jim Guest

    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
     
    Jim, Apr 10, 2004
    #1
    1. Advertising

  2. On Sat, 10 Apr 2004 13:48:16 -0400, Jim wrote:

    > 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'. ;-)

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Apr 10, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=

    How to format "Drop Down List" TextFields and ValueFields?

    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 4, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    13,172
    Eliyahu Goldin
    Jul 4, 2005
  2. J. Albers

    accessing textfields

    J. Albers, Jan 16, 2004, in forum: Java
    Replies:
    5
    Views:
    390
    J. Albers
    Jan 20, 2004
  3. SteKel2002
    Replies:
    0
    Views:
    431
    SteKel2002
    Dec 21, 2003
  4. Replies:
    1
    Views:
    586
    John Timney \(MVP\)
    Jun 19, 2006
  5. JAPIO
    Replies:
    3
    Views:
    113
    JAPIO
    Nov 18, 2005
Loading...

Share This Page