This component uses implementations of the
EditorKit to accomplish its behavior. It effectively
morphs into the proper kind of text editor for the kind
of content it is given. The content type that editor is bound
to at any given time is determined by the EditorKit currently
installed. If the content is set to a new URL, its type is used
to determine the EditorKit that should be used to
load the content.
By default, the following types of content are known:
DefaultEditorKit that produces a wrapped plain text view.
javax.swing.text.html.HTMLEditorKit
which provides HTML 3.2 support.
javax.swing.text.rtf.RTFEditorKit
which provides a limited support of the Rich Text Format.
There are several ways to load content into this component.
setText method can be used to initialize
the component from a string. In this case the current
EditorKit will be used, and the content type will be
expected to be of this type.
read method can be used to initialize the
component from a Reader. Note that if the content type is HTML,
relative references (e.g. for things like images) can't be resolved
unless the <base> tag is used or the Base property
on HTMLDocument is set.
In this case the current EditorKit will be used,
and the content type will be expected to be of this type.
setPage method can be used to initialize
the component from a URL. In this case, the content type will be
determined from the URL, and the registered EditorKit
for that content type will be set.
Some kinds of content may provide hyperlink support by generating
hyperlink events. The HTML EditorKit will generate
hyperlink events if the JEditorPane is not editable
(JEditorPane.setEditable(false); has been called).
If HTML frames are embedded in the document, the typical response would be
to change a portion of the current document. The following code
fragment is a possible hyperlink listener implementation, that treats
HTML frame events specially, and simply displays any other activated
hyperlinks.
class Hyperactive implements HyperlinkListener {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
JEditorPane pane = (JEditorPane) e.getSource();
if (e instanceof HTMLFrameHyperlinkEvent) {
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)e;
HTMLDocument doc = (HTMLDocument)pane.getDocument();
doc.processHTMLFrameHyperlinkEvent(evt);
} else {
try {
pane.setPage(e.getURL());
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
}
For information on customizing how text/html is rendered please see
W3C_LENGTH_UNITS and HONOR_DISPLAY_PROPERTIES
Culturally dependent information in some documents is handled through
a mechanism called character encoding. Character encoding is an
unambiguous mapping of the members of a character set (letters, ideographs,
digits, symbols, or control functions) to specific numeric code values. It
represents the way the file is stored. Example character encodings are
ISO-8859-1, ISO-8859-5, Shift-jis, Euc-jp, and UTF-8. When the file is
passed to an user agent (JEditorPane) it is converted to
the document character set (ISO-10646 aka Unicode).
There are multiple ways to get a character set mapping to happen
with JEditorPane.
setContentType method. If the content
is loaded by the setPage method the content
type will have been set according to the specification of the URL.
It the file is loaded directly, the content type would be expected to
have been set prior to loading.
EditorKit.read operation throw a
ChangedCharSetException which will
be caught. The read is then restarted with a new Reader that uses
the character set specified in the ChangedCharSetException
(which is an IOException).
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Class and Description |
|---|---|
| protected class | JEditorPane.
This class implements accessibility support for the
|
| protected class | JEditorPane.
This class provides support for |
| pack-priv static class | |
| protected class | JEditorPane.
What's returned by
|
| pack-priv class | JEditorPane.
Loads a stream into the text document model. |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final Map | |
| public static final String | HONOR_DISPLAY_PROPERTIES
Key for a client property used to indicate whether the default font and foreground color from the component are used if a font or foreground color is not specified in the styled text. |
| private boolean | |
| private EditorKit | kit
Current content binding of the editor. |
| private static final Hashtable | |
| private static final Hashtable | |
| private static final Hashtable | |
| private SwingWorker | |
| private Hashtable | |
| pack-priv static final String | PostDataProperty
Should be kept in sync with javax.swing.text.html.FormView counterpart. |
| private Hashtable | typeHandlers
Table of registered type handlers for this editor. |
| private static final String | |
| public static final String | W3C_LENGTH_UNITS
Key for a client property used to indicate whether w3c compliant length units are used for html rendering. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | JEditorPane(String
the URL url)Creates a |
| public | JEditorPane(String
mime type of the given text type, String the text to initialize with; may be text)nullCreates a |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | addHyperlinkListener(HyperlinkListener
the listener listener)Adds a hyperlink listener for notification of any changes, for example when a link is selected and entered. |
| protected EditorKit | Returns: the editor kitCreates the default editor kit ( |
| public static EditorKit | Returns: the editor kit, ornull if there is nothing
registered for the given typethe content type type)Creates a handler for the given type from the default registry of editor kits. |
| public void | fireHyperlinkUpdate(HyperlinkEvent
the event e)Notifies all listeners that have registered interest for notification on this event type. |
| public AccessibleContext | Returns: an AccessibleJEditorPane that serves as the AccessibleContext of this JEditorPaneOverrides javax. Implements javax. Gets the AccessibleContext associated with this JEditorPane. |
| private int | getAsynchronousLoadPriority(Document doc)
Return load priority for the document or -1 if priority not supported. |
| public final String | Returns: the content type,null if no editor kit setGets the type of content that this editor is currently set to deal with. |
| public EditorKit | |
| public static String | Returns: aString containing the EditorKit class name
for typethe non- type)null content typeReturns the currently registered |
| public EditorKit | Returns: the editor kitthe non- type)null content typeFetches the editor kit to use for the given type of content. |
| public synchronized HyperlinkListener[] | Returns: all of theHyperLinkListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public URL | |
| private Object | |
| public Dimension | Returns: aDimension containing the preferred sizeOverrides javax. Returns the preferred size for the |
| public boolean | Returns: true if a viewport should force theScrollable's height to match its own,
false otherwiseOverrides javax. Implements javax. Returns true if a viewport should always force the height of this
|
| public boolean | Returns: true if a viewport should force the Scrollables width to match its own, false otherwiseOverrides javax. Implements javax. Returns true if a viewport should always force the width of this
|
| protected InputStream | |
| public String | Returns: the textOverrides javax. Returns the text contained in this |
| public String | Returns: the string "EditorPaneUI"Overrides javax. Gets the class ID for the UI. |
| private void | handleConnectionProperties(URLConnection conn)
Handle URL connection properties (most notably, content type). |
| private void | |
| private Document | initializeModel(EditorKit kit, URL page)
Create model and initialize document properties from page properties. |
| protected String | Returns: a string representation of thisJEditorPaneOverrides javax. Returns a string representation of this |
| public void | read(InputStream
the stream from which to read in, Object an object describing the stream desc)This method initializes from a stream. |
| pack-priv void | read(InputStream
the inputstream to use in, Document the document to load doc)This method invokes the |
| public static void | registerEditorKitForContentType(String
the non- type, String null content typethe class to load later classname)Establishes the default bindings of |
| public static void | registerEditorKitForContentType(String
the non- type, String null content typethe class to load later classname, ClassLoader the loader)ClassLoader to use to load the nameEstablishes the default bindings of |
| public synchronized void | |
| public void | replaceSelection(String
the content to replace the selection with. This
value can be content)nullOverrides javax. Replaces the currently selected content with new content represented by the given string. |
| public void | scrollToReference(String
the named location to scroll to reference)Scrolls the view to the given reference location
(that is, the value returned by the |
| private void | setCharsetFromContentTypeParameters(String paramlist)
This method gets the charset information specified as part of the content type in the http header information. |
| public final void | setContentType(String
the non- type)null mime type for the content editing
supportSets the type of content that this editor handles. |
| public void | setEditorKit(EditorKit
the desired editor behavior kit)Sets the currently installed kit for handling content. |
| public void | setEditorKitForContentType(String
the non- type, EditorKit null content typethe editor kit to be set k)Directly sets the editor kit to use for the given type. |
| public void | |
| public void | |
| public void | setText(String
the new text to be set; if t)null the old
text will be deletedOverrides javax. Sets the text of this |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See |