Skip to main content

JTextPane: getting word under mouse cursor

No replies
emzic
Offline
Joined: 2006-04-21

hello,
i was wondering if there is a possibility to get the word under the mouse cursor in a JTextPane.

i was trying to work with getSelectionStart() and then searching forwards and backwards for the next whitespace, but unfortunately the index returned by the selectionfunctions do not fit to the String that is returned with getText(). there seems to be some kind of offset maybe caused by linebreaks?

thanks!