Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start Cursor in first Position of JTextField

Status
Not open for further replies.

ma2329

MIS
Dec 3, 2001
3
US
Is there any way when u click a JTextField to start at the beginning of the field when the text is already populated in the field? I was thinking of adding it to my Focus Gained method but I don't know which function to use. Any help would be greatly appreciated.

Thank you!
 
Add a FocusListener to your JTextField. implement the focusGained method and just use the mehod setCaretPosition( int pos ) on JTextField to set the position of your cusror to the first position.

Now, for the bummer part. I too have tried doing this, and have found that it works well when working with 1.3. However, there seem to have been some changes introduces into 1.4 that break the ability to do this. I would give it a shot either way, but if you are using 1.4 and this doesn't work, you'll know why.

-gc "I don't look busy because I did it right the first time."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top