I would like to move the mouse cursor from one position to another within a Jtextfield after a condition is satisfied.

I do not know what to use. Thank you

I would like to move the mouse cursor from one position to another within a Jtextfield after a condition is satisfied.

I do not know what to use. Thank you

have you checked:

int offset;
//set int to whatever
jtextfieldname.setCaretPosition(offset);//use setCaretPosition() to move the caret to a specific offset in the jTextField

also i guess this would be of help:http://www.java-examples.com/get-current-caret-position-jtextfield-example

you mean like moving it to another jtextfield all components based elements in java should have a method

requestFocus(boolean temporary)

So to move the cursor to another component when condition is acomplished, you simply set it to true

boolean yourCondition = true;
 yourJtextField.requestFocus(yourCondition);

hope it helps.

have you checked:

int offset;
//set int to whatever
jtextfieldname.setCaretPosition(offset);//use setCaretPosition() to move the caret to a specific offset in the jTextField

also i guess this would be of help:http://www.java-examples.com/get-current-caret-position-jtextfield-example

yes i did use the method setCaretPosition, but nothing is happening... I will have a look at your link thanks

you mean like moving it to another jtextfield all components based elements in java should have a method

requestFocus(boolean temporary)

So to move the cursor to another component when condition is acomplished, you simply set it to true

boolean yourCondition = true;
 yourJtextField.requestFocus(yourCondition);

hope it helps.

No I don't want to move the cursor to another component, but within the same JTexfield.

thanks for the reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.