How to use the <a href> tag in JTextPane

I have a JTextPane that displays a link where a click should open a page in a browser.

The link is set as text in a TextPane , as shown below:

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

Also shown below is how the link looks in my panel:

When I click on it, nothing happens, does anyone know why?

+4
source share
2 answers

Either JTextPane must be non-editable, as indicated by BegemoT, or you can use this http://java-sl.com/tip_links_in_editable.html to allow links in the editable area.

+3
source

You need the JTextPane not to be edited for the activation link and to install the HyperlinkListener on it to provide the action that should be performed when the link is clicked.

+3
source

All Articles