|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
![]()
![]()
![]()
java.awt.Container
![]()
![]()
![]()
javax.swing.JComponent
![]()
![]()
![]()
javax.swing.text.JTextComponent
![]()
![]()
![]()
javax.swing.JEditorPane
, MenuContainer
, Serializable
, Accessible
, Scrollable


public class JEditorPane

A text component to edit various kinds of content. You can find how-to information and examples of using editor panes in Using Text Components, a section in The Java Tutorial.
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.
EditorKit will be used, and the content type will be
expected to be of this type.
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.
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.
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:
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 JavaBeansTM
has been added to the java.beans package.
Please see XMLEncoder
.
| Nested Class Summary | |
|---|---|
protected class |
JEditorPane.AccessibleJEditorPane
This class implements accessibility support for the JEditorPane class. |
protected class |
JEditorPane.AccessibleJEditorPaneHTML
This class provides support for AccessibleHypertext,
and is used in instances where the EditorKit
installed in this JEditorPane is an instance of
HTMLEditorKit. |
protected class |
JEditorPane.JEditorPaneAccessibleHypertextSupport
What's returned by AccessibleJEditorPaneHTML.getAccessibleText. |
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent ![]() |
|---|
JTextComponent.AccessibleJTextComponent |
Nested classes/interfaces inherited from class javax.swing.JComponent ![]() |
|---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container ![]() |
|---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component ![]() |
|---|
Component.AccessibleAWTComponent |
| Field Summary | |
|---|---|
static 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. |
static String |
W3C_LENGTH_UNITS
Key for a client property used to indicate whether w3c compliant length units are used for html rendering. |
Fields inherited from class javax.swing.text.JTextComponent ![]() |
|---|
DEFAULT_KEYMAP |
Fields inherited from class javax.swing.JComponent ![]() |
|---|
accessibleContext |
Fields inherited from class java.awt.Component ![]() |
|---|
BOTTOM_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
JEditorPane
Creates a new JEditorPane. |
|
JEditorPane
Creates a JEditorPane based on a string containing
a URL specification. |
|
JEditorPane
Creates a JEditorPane that has been initialized
to the given text. |
|
JEditorPane
Creates a JEditorPane based on a specified URL for input. |
|
| Method Summary | |
|---|---|
void |
addHyperlinkListener
Adds a hyperlink listener for notification of any changes, for example when a link is selected and entered. |
protected EditorKit |
createDefaultEditorKit
Creates the default editor kit ( PlainEditorKit) for when
the component is first created. |
static EditorKit |
createEditorKitForContentType
Creates a handler for the given type from the default registry of editor kits. |
void |
fireHyperlinkUpdate
Notifies all listeners that have registered interest for notification on this event type. |
AccessibleContext |
getAccessibleContext
Gets the AccessibleContext associated with this JEditorPane. |
String |
getContentType
Gets the type of content that this editor is currently set to deal with. |
EditorKit |
getEditorKit
Fetches the currently installed kit for handling content. |
static String |
getEditorKitClassNameForContentType
Returns the currently registered EditorKit
class name for the type type. |
EditorKit |
getEditorKitForContentType
Fetches the editor kit to use for the given type of content. |
HyperlinkListener |
getHyperlinkListeners
Returns an array of all the HyperLinkListeners added
to this JEditorPane with addHyperlinkListener(). |
URL |
getPage
Gets the current URL being displayed. |
Dimension |
getPreferredSize
Returns the preferred size for the JEditorPane. |
boolean |
getScrollableTracksViewportHeight
Returns true if a viewport should always force the height of this Scrollable to match the height of the viewport. |
boolean |
getScrollableTracksViewportWidth
Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport. |
protected InputStream |
getStream
Fetches a stream for the given URL, which is about to be loaded by the setPage method. |
String |
getText
Returns the text contained in this TextComponent
in terms of the
content type of this editor. |
String |
getUIClassID
Gets the class ID for the UI. |
protected String |
paramString
Returns a string representation of this JEditorPane. |
void |
read
This method initializes from a stream. |
static void |
registerEditorKitForContentType
Establishes the default bindings of type to
classname. |
static void |
registerEditorKitForContentType
Establishes the default bindings of type to
classname. |
void |
removeHyperlinkListener
Removes a hyperlink listener. |
void |
replaceSelection
Replaces the currently selected content with new content represented by the given string. |
void |
scrollToReference
Scrolls the view to the given reference location (that is, the value returned by the UL.getRef
method for the URL being displayed). |
void |
setContentType
Sets the type of content that this editor handles. |
void |
setEditorKit
Sets the currently installed kit for handling content. |
void |
setEditorKitForContentType
Directly sets the editor kit to use for the given type. |
void |
setPage
Sets the current URL being displayed. |
void |
setPage
Sets the current URL being displayed. |
void |
setText
Sets the text of this TextComponent to the specified
content,
which is expected to be in the format of the content type of
this editor. |
Methods inherited from class javax.swing.text.JTextComponent ![]() |
|---|
addCaretListener |