• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get the cursor at the end of the text in a JTextField  RSS feed

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,
I have a simple question.
I have a JTextField where I have set the text as "ICODE". When the program executes I want the cursor to be there at the end of the word "ICODE".
I tried using grabFocus method. But it is not working.
Thanks in advanced....
 
Abhik Sarkar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After initializing the text of the JTextField, call

Hmmm, this might also work in a slightly more efficient way...

[ July 28, 2003: Message edited by: Abhik Sarkar ]
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way is to implement FocusListener. Try the following code:
public void FocusGained(FE fe)
{
java.awt.Robot.keyRelease(KeyEvent.VK_END);
}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!