Search code examples
javaswinghrefjtextpane

How to use <a href> tag in JTextPane


I have a JTextPane which displays a link to which on click should open a page in the browser.

The link is set as a text to the TextPane as shown:

<a href=http://www.google.com target=_blank>Read more..</a>

Also below shows how the link looks like in my pane:

When I click on this nothing happends, do anyone know why?


Solution

  • Either the JTextPane should be non-editable as it's stated by BegemoT or you can use this http://java-sl.com/tip_links_in_editable.html to allow links in editable pane.