Mad_Matt
Mad_Matt

Reputation: 75

How to insert a 'String' in a 'JTextField' to a specific position?

I want to insert a String in a JTextField. Something like-

myTextField.insert(text, position);

How can it be done? Is there any simple way to do this?

Upvotes: 5

Views: 2756

Answers (1)

Mohayemin
Mohayemin

Reputation: 3870

You may do this-

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

And jTextField will show-

This is swing.

Upvotes: 11

Related Questions