Subscribe to RSS Feed
Twitter
HIRE ME! home  archives  about  blogroll

HyperlinkListener.

14 Jan 2005

Ever wondered how to open link in you’re default browser from a JTextPane? Well I did. :)
Here’s a solution I came up with via a Javaworld article:

public class AHyperlinkListener implements HyperlinkListener {   public void hyperlinkUpdate(HyperlinkEvent event) {     if (event.getEventType() == EventType.ACTIVATED) {       //this is windows only off course       String cmd = "rundll32 url.dll,FileProtocolHandler "          + event.getURL();       try {         Process p = Runtime.getRuntime().exec(cmd);       } catch (IOException e) {         e.printStackTrace();         //Do something       }     }   } }

I also have been playing with launch4J, great stuff, it’s very easy to use and works like a charm. In case you’ve never heard of it, it is a Windows native executable java application wrapper.

blog comments powered by Disqus