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.
As you can see in Figure
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.
The view factory implementation for HTML.
Action for inserting
HTML into an existing document.
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>© 2002, O'Reilly & 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 ...