0

I can do it with a JLabel or a JButton, but can't figure out how in a JTextField. I thought I had found it (txtLonDay.setHorizontalAlignment(JTextField.CENTER)), but that doesn't work the way I want. I want all text entered in the field to be centered, and also all text that is displayed in the field, having been produced by the program. These JTextFields are serving double duty; they accept input and also display the results of processing.

Thanks in advance,

Chuck

Don't force it... Get a bigger hammer!

6
Contributors
8
Replies
15
Views
12 Years
Discussion Span
Last Post by hfx642
0

subclass it to provide the behaviour you want.

Thanks... Where could I find an example of that?

Chuck

0

Why don't you take the number of characters the textfield is long, and how many characters the input is long, and formulate a center point out of that...Of course I would rather use setHorizontalAlignment();

0

Why don't you take the number of characters the textfield is long, and how many characters the input is long, and formulate a center point out of that...Of course I would rather use setHorizontalAlignment();

Thanks; I had considered doing that, but I (accidentally) found my real problem: The class I was filling the textfield from had an extra /t (tab) in it. When I took that out, everything worked the way I expected.

The punctuation always throws me... :o

1

@cbrolly21 ... serious..
the last post here was in april 2005 ... not to mention the facts that
a. what you suggested here, has already been suggested before
b. the OP already said his problem was solved

so ... how exactly does this post contribute to the thread?

1

Try...

txtName.setHorizontalAlignment(JLabel.CENTER);

I usually do this for JLabels, but is works on JTextFields as well.

Edited by hfx642: n/a

Votes + Comments
SwingUtilities is there
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.