O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

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

HTML and JEditorPane

As we discussed in Chapter 19, Swing provides (somewhat spotty) support for working with the Web’s most common markup language, HTML. Fortunately, as Swing matures, the HTML support in the JEditorPane class improves.

The support for reading, writing, and displaying HTML through the JEditorPane class is provided by the HTMLEditorKit and associated classes. This class is an extension of the generic DefaultEditorKit class and is devoted (not surprisingly) to HTML files. You might recall from the previous discussion of EditorKit that there are three basic parts of an editor kit: its parser, its file writer, and its association with a ViewFactory. While we have looked briefly at these pieces before, here we focus on their implementation in HTMLEditorKit.

Along the way, we’ll see how to extend some of these pieces to do custom work in the context of an HTML document. We decided that a detailed discussion of the classes that extend the editor kit would not be interesting to a majority of our readers, so we concentrate on the more immediately useful classes. However, if you want to see the details and play with the internals of the HTMLEditorKit, we have two entire chapters devoted to this topic on the book’s web site (http://www.oreilly.com/catalog/jswing2). Throughout this discussion, we’ll point you to that material if you want more detail than we’ve provided here.

Much of the information in those chapters describes how you can extend HTML with custom tags. Adding ...

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