This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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.
 
jQuery in Action, 2nd edition
 
subject: Justifying text
 
Similar Threads
String to integer??
how to increase the size of the text field and change its position ?
Bean to UI Mapping
Help to align Right :eek:
can i postion the cursor.................