How to use setCaretPosition in Jformattedtextfield?

Asked

Viewed 104 times

1

I’m having trouble to "set" the cursor at the beginning of the field, using the setCaretPosition(0); in Textfield fields, it works correctly, but in any field with masking (Jformattedtextfield type), it does not work.

Can anyone tell me why ?

  • Doesn’t work like?

  • It does not arrow the cursor at the beginning of the field, in the case at position 0.

  • And arrow to somewhere? Does it make a mistake? Or just does nothing?

  • 1

    He doesn’t make mistakes. It simply does not do what it should, when using setCaretPosition(0); it should set the cursor at the beginning of the field when it wins focused. And in my fields with mascara, it does not do this, if you click on the field the cursor stays where you clicked.

  • 1

    I think you need to set a Document so that the cursor always starts at the beginning.

  • Could you please post one MVCE demonstrating the problem? I could not play here (Java 8, in openSuse).

  • @diegofm only make a extends of Plaindocument solves ?

  • http://stackoverflow.com/a/2202073/5524514

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.