Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to activate html-links in a JEditor pane

 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

loading and displaying a html-file in a JEditorPane works fine (see code snippet provided),
except for the functionality of html links.

Do I have to provide this functionality separately in a programmatical way, and if yes, how is it accomplished?

 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API for JEditorPane has a code snippet on using HyperlinkListener
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the hint, that should do
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
common links work fine, but having a link referring to an email-adress like this:

results in the following exception:
java.net.UnknownServiceException: protocol doesn't support input

How can I achieve, that a JEditorPane invokes the default email program if clicking on that link?
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Jung wrote:results in the following exception:
java.net.UnknownServiceException: protocol doesn't support input

When? From your own code or from the API's code? Posting the stack trace may help.
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it comes from Sun's API. Complete stack trace is:



I used exactly the code snippet from the JEditorPane-API Maneesh suggested.
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The setPage method does not work for mailto URLs.

In the HyperlinkListener get the protocol of the URL. If that is "mailto" don't call setPage but use Desktop.mail(URL) instead.
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
In the HyperlinkListener get the protocol of the URL. If that is "mailto" don't call setPage but use Desktop.mail(URL) instead.


Thanks, that works ! A very nice new 1.6-feature I didn't know before.
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any API-constant specifiying the protocol "mailto" for html-links, so I don't have to hard-code this (see following code-snippet)?


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic