Skip to Main Content
Java Swing, 2nd Edition
book

Java Swing, 2nd Edition

by Dave Wood, Robert Eckstein, Marc Loy, James Elliott, Brian Cole
November 2002
Intermediate to advanced content levelIntermediate to advanced
1278 pages
38h 26m
English
O'Reilly Media, Inc.
Content preview from Java Swing, 2nd Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Threads, 3rd Edition

Java Threads, 3rd Edition

Scott Oaks, Henry Wong

Publisher Resources

ISBN: 0596004087Errata PageSupplemental Content