How to insert a "String" in a "JTextField" at a specific position?

I want to paste Stringin JTextField. Sort of -

myTextField.insert(text, position);

How can I do that? Is there an easy way to do this?

+5
source share
1 answer

You can do it -

jTextField.setText("This  swing.");    
jTextField.getDocument().insertString(5, "is", null);

And it jTextFieldwill show -

This is a swing.

+9
source

All Articles