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

Set Cursor Position after Text in AWT Textfield  RSS feed

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java 1.1, AWT (no Swing, please)
I'm using the constructor TextField("http://");
This component has the focus.
I want to automatically place the cursor after the 'http://'
Can it be done in AWT?
Thank you!
Drew
 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a handy method called setCaretPosition() that should do the trick. It takes an "int" parameter for the position of the caret (cursor). Anything bigger than the length of the text will cause the caret to appear at the end, so I would use:
setCaretPosition(Integer.MAX_VALUE);
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very nice.
Thank you!
Drew
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!