Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea - Determine index / position from MouseEvent

 
Peter Taucher
Ranch Hand
Posts: 174
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right click does not change the care position.
Try
 
Peter Taucher
Ranch Hand
Posts: 174
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic