This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTextArea - Determine index / position from MouseEvent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea - Determine index / position from MouseEvent" Watch "JTextArea - Determine index / position from MouseEvent" New topic
Author

JTextArea - Determine index / position from MouseEvent

Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
I wanted to add a MouseListener to a JTextArea. In the mousePressed method I'd like to select the current word where the mouse cursor points to. Clicking with the left mouse button I could call 'JTextArea#getCaretPosition' to determine the index / position. But that doesn't work with the right mouse button.

So here comes my question: Isn't there a possibility to get the index / position from the Point of a mouse click (e.g. like JList#locationToIndex)?


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

Right click does not change the care position.
Try


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
Thank you very much Maneesh, that's exactly what I was looking for. I must have overlooked the 'viewToModel' (JTextComponent). So thanks and have a nice day ; - )
 
Don't get me started about those stupid light bulbs.
 
subject: JTextArea - Determine index / position from MouseEvent
 
Similar Threads
MouseListener - mouseEntered question.
setEditable and blinking cursor
obtaining mouse pointer position within a document
Is it a 3 or 2 button mouse?
how to get text under current corsor position