Search code examples
javaswinghyperlinkcursorjeditorpane

Determining XY location of text within multi-line text components


I have a multi-line paragraph displayed in a JEditorPane with certain words within them hyperlinked. I have custom HyperlinkListeners attached to these links that, among other things, returns the location of the cursor on the screen when they are clicked.

I want to get this information when the JEditorPanes are initialized, before the links are clicked. How might I go about doing this?


Solution

  • If you can find the words in the model then you can use:

    Point p = editorPane.modelToView( ... );