4

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?

Bitmap
  • 12,402
  • 16
  • 64
  • 91

2 Answers2

3

You need JTextPane to be non-editable for link to activate, and install HyperlinkListener on it to provide action which should be done when link clicked.

BegemoT
  • 3,776
  • 1
  • 24
  • 30
3

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.

StanislavL
  • 56,971
  • 9
  • 68
  • 98