Converting a mouse position to the caret position of a JTextComponent can be done by using the JTextComponent method viewToModel(). This can be pretty useful if you need to set the caret position of the component when you do a right click of the mouse.

The component can apply to JTextArea, JEditorPane and JTextPane respectively.

Related Posts Plugin for WordPress, Blogger...