• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the char index under the mouse cursor in a JTextComponent?

 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I created an editor where the user is able to put some properties in the text.

Some portions of text have some properties, some don't. I wish to display the available text properties when the mouse cursor hovers over the text. To to that, I need to know what is the char index under the mouse cursor.

How can I do that?
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The (superclass) JTextComponent has two handy methods: viewToModel and modelToView.
 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! It works like a charm.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic