javaswingurljeditorpane

How to show URLs as clickable in JEditorpane and allow them to opened in default browser?


I have Java Desktop application that displays some information in a JTable that contains URL + text in the each cell. As I am facing difficulties to show and open URL in cell so I am planning to show the content of cell in JEditorpane. User can open the content of cell in JEditorpane where user can easily see and edit the content.

Again how can I make only the URL click-able and allow the user to open URL in a default browser in JEditorpane.

Please note:

  1. JEditorpane pane will contain both text and URL so I need to make only URL click-able.
  2. The JEditorpane is editable. User can edit the content.

Solution

    1. Implement an HyperlinkListener. E.G. in JavaDocs for JEditorPane.
    2. Ensure the JEP is displaying HTML, has a content type of text/html, and is not editable.
    3. On event, Desktop.browse(URI) to the URL.