import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class JEditorPaneExample extends JFrame implements HyperlinkListener {
private JEditorPane htmlPane;
public JEditorPaneExample(String url) {
try {
htmlPane = new JEditorPane(url);
} catch (IOException e) {
e.printStackTrace();
}
htmlPane.setEditable(false);
htmlPane.addHyperlinkListener(this);
this.add(new JScrollPane(htmlPane));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(600, 500);
this.setVisible(true);
}
public void hyperlinkUpdate(HyperlinkEvent event) {
HyperlinkEvent.EventType typ = event.getEventType();
if (typ == HyperlinkEvent.EventType.ACTIVATED) {
try {
String url = event.getURL().toString();
new ProcessBuilder("rundll32", "url.dll,FileProtocolHandler",
url).start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new JEditorPaneExample("http://www.tutorials.de");
}
}