954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to move a mouse cursor from one position to another within a Jtexfield in java

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

jkembo
Newbie Poster
8 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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

DavidKroukamp
Practically a Master Poster
Team Colleague
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
 

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.

RicardoE
Junior Poster in Training
73 posts since Jan 2010
Reputation Points: 21
Solved Threads: 7
 

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

jkembo
Newbie Poster
8 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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

jkembo
Newbie Poster
8 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: