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

The HTMLEditorKit Class

The API for the HTMLEditorKit is more or less what you might expect from an editor kit if you made it through Chapter 19-Chapter 22 on Swing text components. We’ll take a brief look at the API and then go through examples of how to work with this editor kit.

Inner Classes

As you can see in Figure 23-7, HTMLEditorKit defines several inner classes. These inner classes are integral to the display and editing of HTML content. While we don’t want to spend too much time on the details of these classes, you should know about them. We list them here as a quick reference.

public static class HTMLEditorKit.HTMLFactory

The view factory implementation for HTML.

public static class HTMLEditorKit.HTMLTextAction

An Action for inserting HTML into an existing document.

public static class HTMLEditorKit.InsertHTMLTextAction

An extension of HTMLTextAction that allows you to insert arbitrary HTML content. This one is quite handy. For example, we can create an action for a toolbar or menu that inserts a copyright:

private final static String COPY_HTML =
  "<p>&copy; 2002, O'Reilly &amp; Associates</p>";
Action a = new HTMLEditorKit.InsertHTMLTextAction("InsertCopyright", 
    COPY_HTML, HTML.Tag.BODY, HTML.Tag.P);
a.putValue(Action.SMALL_ICON, new ImageIcon("icons/cpyrght.gif"));
a.putValue(Action.NAME, "Copyright Text");

The action can be added to a toolbar or menu, just like the others in the StyledEditor example. We end up with a one-touch button that adds our copyright information to the ...

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