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!