JTextField: how to set text to the left of JTextField if the text is too long

I have a long Stringone that I want to display in JTextField. If Stringtoo long, it shows the right side String, not the left side, even if I usesetHorizontalAlignment(JTextField.LEFT)

For example, if my example is String "JTextField, this text is too long , it should display as ...

|----------------------|
| JTextField example ..|
|----------------------|

but instead, it appears as ...

|----------------------|
| this text is too long|
|----------------------|

Can someone suggest how this can be fixed.

+5
source share
1 answer

horizontalAlignement works great when the size of the field is greater than the number of characters in the string, but if it is smaller, then only LEFT_ALIGNMENT with setText to create it, and not with any later setText.

, :

myTextField.setCaretPosition(0);
+8

All Articles