| 
Swing 1.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | 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
A text component to edit various kinds of content. 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:
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.
For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JEditorPane key assignments.
 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 
 (i.e. 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();
}
}
}
}
}
 
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.
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. A future release of Swing will provide support for long term persistence.
| Inner Class Summary | |
protected  class | 
JEditorPane.AccessibleJEditorPane
The class used to obtain the accessible role for this object.  | 
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() Provides support for AccessibleHypertext in case there is an HTML document being displayed in this JEditorPane.  | 
| Inner classes inherited from class javax.swing.text.JTextComponent | 
JTextComponent.AccessibleJTextComponent,  
JTextComponent.KeyBinding | 
| Inner classes inherited from class javax.swing.JComponent | 
JComponent.AccessibleJComponent | 
| Fields inherited from class javax.swing.text.JTextComponent | 
DEFAULT_KEYMAP,  
FOCUS_ACCELERATOR_KEY | 
| Fields inherited from class javax.swing.JComponent | 
accessibleContext,  
listenerList,  
TOOL_TIP_TEXT_KEY,  
ui,  
UNDEFINED_CONDITION,  
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,  
WHEN_FOCUSED,  
WHEN_IN_FOCUSED_WINDOW | 
| Fields inherited from class java.awt.Component | 
BOTTOM_ALIGNMENT,  
CENTER_ALIGNMENT,  
LEFT_ALIGNMENT,  
RIGHT_ALIGNMENT,  
TOP_ALIGNMENT | 
| Constructor Summary | |
JEditorPane()
Constructs a new JEditorPane.  | 
|
JEditorPane(String url)
Creates a JEditorPane based on a string containing a URL specification.  | 
|
JEditorPane(String type,
            String text)
Creates a JEditorPane that has been initialized to the given text.  | 
|
JEditorPane(URL initialPage)
Creates a JEditorPane based on a specified URL for input.  | 
|
| Method Summary | |
 void | 
addHyperlinkListener(HyperlinkListener listener)
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(String type)
Create a handler for the given type from the default registry of editor kits.  | 
 void | 
fireHyperlinkUpdate(HyperlinkEvent e)
Notifies all listeners that have registered interest for notification on this event type.  | 
 AccessibleContext | 
getAccessibleContext()
Get 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.  | 
 EditorKit | 
getEditorKitForContentType(String type)
Fetches the editor kit to use for the given type of content.  | 
 URL | 
getPage()
Gets the current url being displayed.  | 
 Dimension | 
getPreferredSize()
The preferred size for JEditorPane is slightly altered from the preferred size of the superclass.  | 
 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(URL page)
Fetch 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.  | 
 boolean | 
isManagingFocus()
Turns off tab traversal once focus gained.  | 
protected  String | 
paramString()
Returns a string representation of this JEditorPane.  | 
protected  void | 
processComponentKeyEvent(KeyEvent e)
Make sure that TAB and Shift-TAB events get consumed, so that awt doesn't attempt focus traversal.  | 
 void | 
read(InputStream in,
     Object desc)
This method initializes from a stream.  | 
static void | 
registerEditorKitForContentType(String type,
                                String classname)
Establishes the default bindings of type to name.  | 
static void | 
registerEditorKitForContentType(String type,
                                String classname,
                                ClassLoader loader)
Establishes the default bindings of type to name.  | 
 void | 
removeHyperlinkListener(HyperlinkListener listener)
Removes a hyperlink listener.  | 
 void | 
replaceSelection(String content)
Replaces the currently selected content with new content represented by the given string.  | 
protected  void | 
scrollToReference(String reference)
Scroll the view to the given reference location (i.e.  | 
 void | 
setContentType(String type)
Sets the type of content that this editor handles.  | 
 void | 
setEditorKit(EditorKit kit)
Sets the currently installed kit for handling content.  | 
 void | 
setEditorKitForContentType(String type,
                           EditorKit k)
Directly set the editor kit to use for the given type.  | 
 void | 
setPage(String url)
Sets the current url being displayed.  | 
 void | 
setPage(URL page)
Sets the current url being displayed.  | 
 void | 
setText(String t)
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 java.awt.Container | 
add, 
add, 
add, 
add, 
add, 
addContainerListener, 
addImpl, 
countComponents, 
deliverEvent, 
doLayout, 
getComponent, 
getComponentAt, 
getComponentAt, 
getComponentCount, 
getComponents, 
getLayout, 
insets, 
invalidate, 
isAncestorOf, 
layout, 
list, 
list, 
locate, 
minimumSize, 
paintComponents, 
preferredSize, 
print, 
printComponents, 
processContainerEvent, 
processEvent, 
remove, 
remove, 
removeAll, 
removeContainerListener, 
setLayout, 
validate, 
validateTree | 
| Methods inherited from class java.lang.Object | 
clone, 
equals, 
finalize, 
getClass, 
hashCode, 
notify, 
notifyAll, 
wait, 
wait, 
wait | 
| Constructor Detail | 
public JEditorPane()
public JEditorPane(URL initialPage)
            throws IOException
initialPage - the URL
public JEditorPane(String url)
            throws IOException
url - the URL
public JEditorPane(String type,
                   String text)
setContentType and setText methods.type - mime type of the given text.text - the text to initialize with.| Method Detail | 
public void addHyperlinkListener(HyperlinkListener listener)
listener - the listenerpublic void removeHyperlinkListener(HyperlinkListener listener)
listener - the listenerpublic void fireHyperlinkUpdate(HyperlinkEvent e)
e - the eventEventListenerList
public void setPage(URL page)
             throws IOException
scrollToReference 
 method.  If the desired URL is not the one currently being
 displayed, the getStream method is called to
 give subclasses control over the stream provided.
 
 This may load either synchronously or asynchronously
 depending upon the document returned by the EditorKit.
 If the Document is of type AbstractDocument and has
 a value returned by 
 AbstractDocument.getAsynchronousLoadPriority
 that is greater than or equal to zero, the page will be
 loaded on a seperate thread using that priority.
 
 If the document is loaded synchronously, it will be
 filled in with the stream prior to being installed into
 the editor with a call to setDocument, which
 is bound and will fire a property change event.  If an
 IOException is thrown the partially loaded document will
 be discarded and neither the document or page property
 change events will be fired.  If the document is 
 successfully loaded and installed, a view will be
 built for it by the UI which will then be scrolled if 
 necessary, and then the page property change event
 will be fired.
 
 If the document is loaded asynchronously, the document
 will be installed into the editor immediately using a
 call to setDocument which will fire a 
 document property change event, then a thread will be
 created which will begin doing the actual loading.  
 In this case, the page property change event will not be 
 fired by the call to this method directly, but rather will be 
 fired when the thread doing the loading has finished.
 Since the calling thread can not throw an IOException in
 the event of failure on the other thread, the page 
 property change event will be fired when the other 
 thread is done whether the load was successful or not.
page - the URL of the pagegetPage()
public void read(InputStream in,
                 Object desc)
          throws IOException
in - The stream to read fromdesc - An object describing the stream.JTextComponent.read(java.io.Reader, java.lang.Object), 
JTextComponent.setDocument(javax.swing.text.Document)
protected InputStream getStream(URL page)
                         throws IOException
setPage method.  By
 default, this simply opens the url and returns the
 stream.  This can be reimplemented to do useful things
 like fetch the stream from a cache, monitor the progress
 of the stream, etc.
 This method is expected to have the the side effect of establising the content type, and therefore setting the appropriate EditorKit to use for loading the stream.
protected void scrollToReference(String reference)
UL.getRef
 method for the url being displayed).  By default, this
 method only knows how to locate a reference in an
 HTMLDocument.  The implementation calls the
 scrollRectToVisible method to
 accomplish the actual scrolling.  If scrolling to a
 reference location is needed for document types other
 than html, this method should be reimplemented.
 This method will have no effect if the component
 is not visible.reference - the named location to scroll to.public URL getPage()
public void setPage(String url)
             throws IOException
url - the URL for displaypublic String getUIClassID()
JComponent.getUIClassID(), 
UIDefaults.getUI(javax.swing.JComponent)protected EditorKit createDefaultEditorKit()
public final EditorKit getEditorKit()
public final String getContentType()
public final void setContentType(String type)
getEditorKitForContentType,
 and then setEditorKit if an editor kit can
 be successfully located.  This is mostly convenience method
 that can be used as an alternative to calling 
 setEditorKit directly.
 
 If there is a charset definition specified as a parameter
 of the content type specification, it will be used when
 loading input streams using the associated EditorKit.
 For example if the type is specified as 
 text/html; charset=EUC-JP the content
 will be loaded using the EditorKit registered for
 text/html and the Reader provided to
 the EditorKit to load unicode into the document will
 use the EUC-JP charset for translating
 to unicode.
type - the non-null mime type for the content editing
   support.getContentType()public void setEditorKit(EditorKit kit)
kit - the desired editor behavior.getEditorKit()public EditorKit getEditorKitForContentType(String type)
This method can be reimplemented to use some other kind of type registry. This can be reimplemented to use the Java Activation Framework for example.
type - the non-null content type
public void setEditorKitForContentType(String type,
                                       EditorKit k)
type - the non-null content typek - the editor kit to be setpublic void replaceSelection(String content)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
content - the content to replace the selection withpublic static EditorKit createEditorKitForContentType(String type)
Once a prototype EditorKit instance is successfully located, it is cloned and the clone is returned.
type - the content type
public static void registerEditorKitForContentType(String type,
                                                   String classname)
type - the non-null content typeclassname - the class to load later
public static void registerEditorKitForContentType(String type,
                                                   String classname,
                                                   ClassLoader loader)
type - the non-null content typeclassname - the class to load laterloader - the ClassLoader to use to load the namepublic Dimension getPreferredSize()
public boolean isManagingFocus()
protected void processComponentKeyEvent(KeyEvent e)
public void setText(String t)
text/html
 the string should be specified in terms of html.  This is implemented
 to call JTextComponent.read with a 
 StringReader[
 This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
t - the new text to be setgetText()public String getText()
JTextComponent.write with
 a StringWriter.setText(java.lang.String)public boolean getScrollableTracksViewportWidth()
public boolean getScrollableTracksViewportHeight()
protected String paramString()
null.
 Overriding paramString() to provide information about the specific new aspects of the JFC components.
public AccessibleContext getAccessibleContext()
  | 
Swing 1.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||