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

A Custom EditorKit

Although Swing’s HTML support is less than ideal, it is sufficient to handle inline help systems and aid in rapid prototyping. Each release of the SDK improves support and usability. It will continue to get better. In the meantime, if you’re desperate for serious markup language support, you really should check out XML.

If you’re interested in doing your own EditorKit work, look up the more detailed HTMLEditorKit chapters online. You should also check out the javax.swing.text.rtf package. It serves the same basic purpose as the HTML package but reads and writes RTF files. However, be aware that RTF seems to be even more plagued with “acceptable variants” than HTML. Make sure you test your output on an intended target system before rolling out your new commercial editor!

To round out this final section, we’ll review the steps involved in creating your own editor kit. These steps include:

  • Creating the EditorKit class

  • Defining the Document type

  • Defining new Actions

  • Creating custom View classes

  • Creating a ViewFactory

  • Creating a “reader” and a “writer”

  • Telling JEditorPane about your new kit

Create the EditorKit Class

First, create your EditorKit class. Depending on the type of documents you’re going to support, you can subclass the abstract EditorKit base class or extend any of the existing kits we’ve covered in this chapter.

Much of the work in creating this class is covered in the steps that follow. In addition to those more complex issues, you should implement the following ...

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