Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

To jump a position of the Cursor in the Text  RSS feed

 
sandy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a timeTextField(validated only for TimeInput -> 00:00:00). When the user types in the time, he should be able to skip through the character ':' and goto the next Token in the text. How can this cursor skipping concept be approached ?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sandy" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
Steffen Foldager
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandy
I presume you want "00:00:00" from the beginning?
A way to go would (very) roughly be like this:
Add a key listener:
selectTimeTextField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
doMyStuff(evt);
}
});

Then do the stuff:

public void doMyStuff(){
//1 validate the whole string, including ":"

//2 use getCaretPosition() and setCaretPosition(int) on the TextField.
}

Steffen
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!