Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / July 2005

Tip: Looking for answers? Try searching our database.

JTextField not select all on double-click

Thread view: 
james.goldwater@gmail.com - 27 Jul 2005 16:04 GMT
Is there a way of making a JTextField -not- select all the text when
double-clicked? I'd like to make it just place the caret in the correct
place.  Has anyone any pointers?
Alex Molochnikov - 27 Jul 2005 16:51 GMT
Set up the mouse listener for the field. In the mouseClicked() method, check
the click count of the event. If the count is 1, get the cursor position. If
the count is 2 (the double-click), deselect text in the field, and set the
cursor position to what it was at the click count 1. The docs will provide
the necessary detail.

By implementing this logic, you will break the paradigm of selecting text in
the text field, which is always a bad idea.

HTH

Alex Molochnikov
Gestalt Corporation

> Is there a way of making a JTextField -not- select all the text when
> double-clicked? I'd like to make it just place the caret in the correct
> place.  Has anyone any pointers?
james.goldwater@gmail.com - 27 Jul 2005 17:52 GMT
Thanks, that works great.  And I agree with the selection paradigm -
except I'm trying to emulate Excel's behaviour!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.