How do you center the text in a JTextField??

Reply

Join Date: Jan 2005
Posts: 10
Reputation: ecyarter is an unknown quantity at this point 
Solved Threads: 0
ecyarter ecyarter is offline Offline
Newbie Poster

How do you center the text in a JTextField??

 
0
  #1
Apr 5th, 2005
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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How do you center the text in a JTextField??

 
0
  #2
Apr 5th, 2005
subclass it to provide the behaviour you want.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 10
Reputation: ecyarter is an unknown quantity at this point 
Solved Threads: 0
ecyarter ecyarter is offline Offline
Newbie Poster

Re: How do you center the text in a JTextField??

 
0
  #3
Apr 5th, 2005
Originally Posted by jwenting
subclass it to provide the behaviour you want.

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

Chuck
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: How do you center the text in a JTextField??

 
0
  #4
Apr 5th, 2005
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();
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 10
Reputation: ecyarter is an unknown quantity at this point 
Solved Threads: 0
ecyarter ecyarter is offline Offline
Newbie Poster

Re: How do you center the text in a JTextField??

 
0
  #5
Apr 5th, 2005
Originally Posted by server_crash
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC