O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JEditorPane

We create a JEditorPane in the blogger application in the Toolkit section. I refer you there to see in detail how that is used. But there is one question that is often asked when figuring out how to use JEditorPanes. And that's how to handle hyperlink clicks.

You do need to do something in fact. If you use a JEditorPane to display a simple HTML page, which is one of its main purposes, nothing will happen when you click on the links. Unless you create an object of a class that implements the HyperlinkListener interface, as shown in the following example:

 try { String url = "http://www.javagarage.net"; JEditorPane editorPane = new JEditorPane(url); //don't let user try to edit content! editorPane.setEditable(false); editorPane.addHyperlinkListener(new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required