How to convert from a mouse position to a character position in a JEditorPane in Java Swing -
I am currently trying to solve a problem where the Zeddercan should find the position in a piece of text where Mouse was clicked.
Actually, when a user right-clicks a word, I need to know what to do in order to do what I need to know in terms of which user Clicked on. I know that I can easily get mouse position from mouseEvent which has passed in the mouse pressed method, and I am told that you can change it to get character index in the piece of text - though I It did not figure out how to do it. The ViewToModel () method has been tried on JEditorPane but it is giving me wrong position in the text, or I am using it wrong or it does not work in this way.
Any thoughts?
encoding viewToModel ()
The correct way to do this is:
Public Zero Mouse Clicked (MouseWave E) {ZDatorPan Editor = (ZdTrapane) E.GetsSoS (); Point Point = New Point (EATAX), EETEGEE ()); Int pos = editor.viewToModel (pt); // whatever you need to do here)
Comments
Post a Comment