aspose file tools*
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
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: 10523
    
    9

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 ; - )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextArea - Determine index / position from MouseEvent