Handling URL protocols in JEditorPane?

F

Frank D. Greco

I have a simple JEditorPane that displays a very simple web page that has an
embedded "mailto:[email protected]"

When the user clicks on this link, I'd like the "usual" thing to happen: the
native email program is invoked to compose an email with the 'To:' line filled
out.

At this point, I don't want to send email directly from my Java app (ie, with
JavaMail). I need to use the native email program, which for my user is MS
Exchange.

I can get the link text when the user clicks on the mailto link, but I'm having
trouble invoking the native email program a la the typical browser.

Any help is appreciated.

Frank
 
F

Filip Larsen

Frank said:
I have a simple JEditorPane that displays a very simple web page that
has an embedded "mailto:[email protected]" [...] I can get the link text
when the user clicks on the mailto link, but I'm having trouble
invoking the native email program a la the typical browser.


I believe you should let the platform handle URL just like if it was a
http URL, so in an applet you would invoke
java.applet.AppletContext.showDocument,
in a WebStart application you would invoke
javax.jnlp.BasicService.showDocument, and in a stand-alone application
you would (still unfortunately, I believe) have to invoke some
platform-specific
command via java.lang.Runtime.exec in order to get the platform to
handle the URL. On Windows that would be something like "cmd.exe /c
start description mailto:[email protected]".


Regards,
 
A

Andrew Thompson

Frank D. Greco wrote: ...

I believe you should let the platform handle URL just like if it was a
http URL, so in an applet you would invoke
java.applet.AppletContext.showDocument,

Unfortunately, showDocument() was never
reliable, and becomes less so as time
goes by.
in a WebStart application you would invoke
javax.jnlp.BasicService.showDocument,

Which at least returns a true/false to
indicate success/failure. It is the
method I prefer to use (easy to do, when
most of my apps. are web start based!).
..and in a stand-alone application
you would (still unfortunately, I believe) have to invoke some
platform-specific
command via java.lang.Runtime.exec in order to get the platform to
handle the URL. On Windows that would be something like "cmd.exe /c
start description mailto:[email protected]".

For that (or a signed applet) I would
look to BrowserLauncher2, which takes a
rigorous approach to finding and launching
the (hopefully) default browser.

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top