2

I'm creating small game for children to teach maths.For that I need JTextField to operate right to left. It mean that If I type "A" then "B" using keyboard, in JTextField it should be display like "BA". I think you guys can get a idea now. Thanks in advance. :)

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
FxMax
  • 472
  • 1
  • 5
  • 9
  • possible duplicate of [How to set the orientation of JTextArea from right to left (inside JOptionPane)](http://stackoverflow.com/questions/6475320/how-to-set-the-orientation-of-jtextarea-from-right-to-left-inside-joptionpane) – Paco Abato Feb 02 '15 at 13:12
  • textField.setCaretPosition(0); Try this – Subhan Feb 02 '15 at 13:14

2 Answers2

7

Use setComponentOrientation method of JTextComponent Class

textField.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
Neeraj Jain
  • 7,643
  • 6
  • 34
  • 62
0

What you ask for is not a feature of JTextfield or its parents.

One way you can get what you want is to use Apache Commons Lang library and class StringUtils.reverse("flip") -> "pilf".

https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#reverse-java.lang.String-

Avec
  • 1,626
  • 21
  • 31