This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Justifying text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Justifying text" Watch "Justifying text" New topic
Author

Justifying text

Adam Vinueza
Ranch Hand

Joined: Apr 16, 2001
Posts: 76
I want to right-justify the text in a JTextField, but am confused. The API says that the method setHorizontalAlignment takes an int value, and also states that LEFT, RIGHT, etc. are valid values for JTextField, but my compiler doesn't seem to recognize these as valid int values. When I write
txtField.setHorizontalAlignment( RIGHT );
I get an error message saying the variable RIGHT isn't recognized. I must have done something wrong, but I don't know what. Help!
Rick Fortier
Ranch Hand

Joined: Jun 04, 2001
Posts: 147
Originally posted by Adam Vinueza:
I want to right-justify the text in a JTextField, but am confused. The API says that the method setHorizontalAlignment takes an int value, and also states that LEFT, RIGHT, etc. are valid values for JTextField, but my compiler doesn't seem to recognize these as valid int values. When I write
txtField.setHorizontalAlignment( RIGHT );
I get an error message saying the variable RIGHT isn't recognized. I must have done something wrong, but I don't know what. Help!

That is a field in the javax.swing.SwingConstants interface. So either you need to import the interface or use javax.swing.SwingConstants.RIGHT instead of plain RIGHT.
 
Consider Paul's rocket mass heater.
 
subject: Justifying text
 
Similar Threads
can i postion the cursor.................
Bean to UI Mapping
Help to align Right :eek:
String to integer??
how to increase the size of the text field and change its position ?