aspose file tools*
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
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Justifying text