Java Reference
In-Depth Information
Note The page property is nonstandard in the sense it has two setter methods, but only one getter.
Four interesting properties of JEditorPane are the editorKit , contentType , page , and text .
The editorKit property is configured based on the type of content in the editor pane. It is
covered in more detail in Chapter 16, with its DefaultEditorKit , StyledEditorKit , and
HTMLEditorKit implementations. The contentType property represents the MIME type of the
content inside the document. This property tends to be automatically set when you set up
the content in the constructor (or elsewhere). In the event the editor kit is unable to determine the
MIME type, you can manually set it. The three MIME types with built-in support are text/html ,
text/plain , and text/rtf , as reported by the getContentType() method of the predefined
editor kits.
The page property allows you to change the displayed contents to reflect the contents of a
specific URL so that you can use the contents in some manner not programmed into the envi-
ronment. The text property allows you to find out what the textual content is based on the
current Document model.
Handling JEditorPane Events
Because JEditorPane is just another text area component with some special display character-
istics, it supports the same set of listeners for event handling as does the JTextArea component.
In addition, the JEditorPane provides a special listener-event combination to deal with hyper-
links within a document.
The HyperlinkListener interface defines one method, public void hyperlinkUpdate
(HyperlinkEvent hyperlinkEvent) , which works with a HyperlinkEvent to respond to—not
surprisingly—a hyperlink event. The event includes a HyperlinkEvent.EventType that reports
on the type of event and allows you to react differently, either by following the link when
selected or possibly changing the cursor when moving the mouse over (or off) the hyperlink
(although this happens by default).
Here is the HyperlinkListener definition:
public interface HyperlinkListener implements EventListener {
public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent);
}
And, here is the HyperlinkEvent definition:
public class HyperlinkEvent extends EventObject {
// Constructors
public HyperlinkEvent(Object source, HyperlinkEvent.EventType type, URL url);
public HyperlinkEvent(Object source, HyperlinkEvent.EventType type, URL url,
String description);
public HyperlinkEvent(Object source, HyperlinkEvent.EventType type, URL url,
String description, Element sourceElement)
// Properties
public String getDescription();
 
Search WWH ::




Custom Search