Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Justifying text

 
Adam Vinueza
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic