• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Justifying text

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic