Java JTextField FAQ - How do I right-align a JTextField?

Java JTextField question: How do I right-align the text in a JTextField?

Short answer:

myTextField.setHorizontalAlignment(SwingConstants.TRAILING);

Long answer: I need to look at this some more to understand the difference between the alignment constants in SwingConstant and the alignment constants in JTextField.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.