Java Platform 1.2
Beta 4

Class com.sun.java.swing.JEditorPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--com.sun.java.swing.JComponent
                    |
                    +--com.sun.java.swing.text.JTextComponent
                          |
                          +--com.sun.java.swing.JEditorPane
Direct Known Subclasses:
JTextPane

public class JEditorPane
extends JTextComponent
A text pane to edit various kinds of content, such as html and rtf. 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.

For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JEditorPane key assignments.

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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
Serialized Form

Inner Class Summary
protected   JEditorPane.AccessibleJEditorPane
          The class used to obtain the accessible role for this object.
protected   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   JEditorPane.JEditorPaneAccesssibleHypertextSupport
          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 com.sun.java.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent , JTextComponent.KeyBinding
 
Inner classes inherited from class com.sun.java.swing.JComponent
JComponent.AccessibleJComponent
 
Fields inherited from class com.sun.java.swing.text.JTextComponent
DEFAULT_KEYMAP , FOCUS_ACCELERATOR_KEY
 
Fields inherited from class com.sun.java.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(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 handles.
 EditorKit getEditorKit()
          Fetches the currently installed kit for handling content. createDefaultEditorKit() is called to set up a default if necessary.
 EditorKit getEditorKitForContentType(String type)
          Fetches the editor kit to use for the given type of content.
 URL getPage()
          Gets the current url being displayed.
 boolean getScrollableTracksViewportWidth()
          Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport.
 String getUIClassID()
          Gets the class ID for the UI.
 boolean isManagingFocus()
          Turns off tab traversal once focus gained.
static void registerEditorKitForContentType(String type, String classname, ClassLoader loader)
          Establishes the default bindings of type to name.
static void registerEditorKitForContentType(String type, String classname)
          Establishes the default bindings of type to name.
 void removeHyperlinkListener(HyperlinkListener listener)
          Removes a hyperlink listener.
protected  void scrollToReference(String reference)
          Scroll the view to the given reference location (i.e. the value returned by the URL.getRef method for the url being displayed).
 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.
 
Methods inherited from class com.sun.java.swing.text.JTextComponent
addCaretListener , addKeymap , copy , cut , fireCaretUpdate , getActions , getCaret , getCaretColor , getCaretPosition , getDisabledTextColor , getDocument , getFocusAccelerator , getHighlighter , getKeymap , getKeymap , getMargin , getPreferredScrollableViewportSize , getScrollableBlockIncrement , getScrollableTracksViewportHeight , getScrollableUnitIncrement , getSelectedText , getSelectedTextColor , getSelectionColor , getSelectionEnd , getSelectionStart , getText , getText , getUI , isEditable , isFocusTraversable , isOpaque , loadKeymap , modelToView , moveCaretPosition , paste , processComponentKeyEvent , read , removeCaretListener , removeKeymap , replaceSelection , select , selectAll , setCaret , setCaretColor , setCaretPosition , setDisabledTextColor , setDocument , setEditable , setEnabled , setFocusAccelerator , setHighlighter , setKeymap , setMargin , setOpaque , setSelectedTextColor , setSelectionColor , setSelectionEnd , setSelectionStart , setText , setUI , updateUI , viewToModel , write
 
Methods inherited from class com.sun.java.swing.JComponent
addAncestorListener , addNotify , addPropertyChangeListener , addVetoableChangeListener , computeVisibleRect , contains , createToolTip , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , firePropertyChange , fireVetoableChange , getActionForKeyStroke , getAlignmentX , getAlignmentY , getAutoscrolls , getBorder , getBounds , getClientProperty , getComponentGraphics , getConditionForKeyStroke , getDebugGraphicsOptions , getGraphics , getHeight , getInsets , getInsets , getLocation , getMaximumSize , getMinimumSize , getNextFocusableComponent , getPreferredSize , getRegisteredKeyStrokes , getRootPane , getSize , getToolTipLocation , getToolTipText , getToolTipText , getTopLevelAncestor , getVisibleRect , getWidth , getX , getY , grabFocus , hasFocus , isDoubleBuffered , isFocusCycleRoot , isLightweightComponent , isOptimizedDrawingEnabled , isPaintingTile , isRequestFocusEnabled , isValidateRoot , paint , paintBorder , paintChildren , paintComponent , paintImmediately , paintImmediately , processFocusEvent , processKeyEvent , processMouseMotionEvent , putClientProperty , registerKeyboardAction , registerKeyboardAction , removeAncestorListener , removeNotify , removePropertyChangeListener , removeVetoableChangeListener , repaint , repaint , requestDefaultFocus , requestFocus , resetKeyboardActions , reshape , revalidate , scrollRectToVisible , setAlignmentX , setAlignmentY , setAutoscrolls , setBorder , setDebugGraphicsOptions , setDoubleBuffered , setMaximumSize , setMinimumSize , setNextFocusableComponent , setPreferredSize , setRequestFocusEnabled , setToolTipText , setUI , setVisible , unregisterKeyboardAction , update
 
Methods inherited from class java.awt.Container
add , add , add , add , add , addContainerListener , addImpl , countComponents , deliverEvent , doLayout , findComponentAt , findComponentAt , getComponent , getComponentAt , getComponentAt , getComponentCount , getComponents , getLayout , insets , invalidate , isAncestorOf , layout , list , list , locate , minimumSize , paintComponents , paramString , preferredSize , print , printComponents , processContainerEvent , processEvent , remove , remove , removeAll , removeContainerListener , setLayout , validate , validateTree
 
Methods inherited from class java.awt.Component
action , add , addComponentListener , addFocusListener , addInputMethodListener , addKeyListener , addMouseListener , addMouseMotionListener , addPropertyChangeListener , bounds , checkImage , checkImage , coalesceEvents , contains , createImage , createImage , disable , disableEvents , dispatchEvent , enable , enable , enableEvents , enableInputMethods , getBackground , getBounds , getColorModel , getComponentOrientation , getCursor , getDropTarget , getFont , getFontMetrics , getForeground , getInputContext , getInputMethodRequests , getLocale , getLocation , getLocationOnScreen , getName , getParent , getPeer , getSize , getToolkit , getTreeLock , gotFocus , handleEvent , hide , imageUpdate , inside , isDisplayable , isEnabled , isLightweight , isShowing , isValid , isVisible , keyDown , keyUp , list , list , list , location , lostFocus , mouseDown , mouseDrag , mouseEnter , mouseExit , mouseMove , mouseUp , move , nextFocus , paintAll , postEvent , prepareImage , prepareImage , printAll , processComponentEvent , processInputMethodEvent , processMouseEvent , remove , removeComponentListener , removeFocusListener , removeInputMethodListener , removeKeyListener , removeMouseListener , removeMouseMotionListener , removePropertyChangeListener , repaint , repaint , repaint , resize , resize , setBackground , setBounds , setBounds , setComponentOrientation , setCursor , setDropTarget , setFont , setForeground , setLocale , setLocation , setLocation , setName , setSize , setSize , show , show , size , toString , transferFocus
 
Methods inherited from class java.lang.Object
clone , equals , finalize , getClass , hashCode , notify , notifyAll , wait , wait , wait
 

Constructor Detail

JEditorPane

public JEditorPane()
Constructs a new JEditorPane. The document model is set to null.

JEditorPane

public JEditorPane(URL initialPage)
            throws IOException
Creates a JEditorPane based on a specified URL for input.
Parameters:
initialPage - the URL
Throws:
IOException - if the URL is null or cannot be accessed

JEditorPane

public JEditorPane(String url)
            throws IOException
Creates a JEditorPane based on a string containing a URL specification.
Parameters:
url - the URL
Throws:
IOException - if the URL is null or cannot be accessed
Method Detail

addHyperlinkListener

public void addHyperlinkListener(HyperlinkListener listener)
Adds a hyperlink listener for notification of any changes, for example when a link is selected and entered.
Parameters:
listener - the listener

removeHyperlinkListener

public void removeHyperlinkListener(HyperlinkListener listener)
Removes a hyperlink listener.
Parameters:
listener - the listener

fireHyperlinkUpdate

public void fireHyperlinkUpdate(HyperlinkEvent e)
Notifies all listeners that have registered interest for notification on this event type. This is normally called by the currently installed EditorKit if a content type that supports hyperlinks is currently active and there was activity with a link. The listener list is processed last to first.
Parameters:
e - the event
See Also:
EventListenerList

setPage

public void setPage(URL page)
             throws IOException
Sets the current url being displayed. The content type of the pane is set, and if the editor kit for the pane is non-null, then a new default document is created and the URL is read into it. If the url contains and reference location, the location will be scrolled to by calling the scrollToReference method.
Parameters:
page - the URL of the page
Throws:
IOException - for a null or invalid page specification

scrollToReference

protected void scrollToReference(String reference)
Scroll the view to the given reference location (i.e. the value returned by the URL.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.
Parameters:
reference - the named location to scroll to.

getPage

public URL getPage()
Gets the current url being displayed. If a URL was not specified in the creation of the document, this will return null, and relative URL's will not be resolved.
Returns:
the URL

setPage

public void setPage(String url)
             throws IOException
Sets the current url being displayed.
Parameters:
url - the URL for display
Throws:
IOException - for a null or invalid URL specification

getUIClassID

public String getUIClassID()
Gets the class ID for the UI.
Returns:
the ID ("EditorPaneUI")
Overrides:
getUIClassID in class JComponent
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(com.sun.java.swing.JComponent)

createDefaultEditorKit

protected EditorKit createDefaultEditorKit()
Creates the default editor kit (PlainEditorKit) for when the component is first created.
Returns:
the editor kit

getEditorKit

public final EditorKit getEditorKit()
Fetches the currently installed kit for handling content. createDefaultEditorKit() is called to set up a default if necessary.
Returns:
the editor kit

getContentType

public final String getContentType()
Gets the type of content that this editor handles.
Returns:
the content type, null if no editor kit set

setContentType

public final void setContentType(String type)
Sets the type of content that this editor handles. This calls getEditorKitForContentType, and then setEditorKit if an editor kit can be successfully located. This is a convenience method that can be used as an alternative to calling setEditorKit directly.
Parameters:
type - the non-null mime type for the content editing support.
See Also:
getContentType()

setEditorKit

public void setEditorKit(EditorKit kit)
Sets the currently installed kit for handling content. This is the bound property that establishes the content type of the editor. Any old kit is first deinstalled, then if kit is non-null, the new kit is installed, and a default document created for it. A PropertyChange event ("editorKit") is always fired when setEditorKit() is called.
Parameters:
kit - the desired editor behavior.
See Also:
getEditorKit()

getEditorKitForContentType

public EditorKit getEditorKitForContentType(String type)
Fetches the editor kit to use for the given type of content. This is called when a type is requested that doesn't match the currently installed type. If the component doesn't have an EditorKit registered for the given type, it will try to create an EditorKit from the default EditorKit registry. If that fails, a PlainEditorKit is used on the assumption that all text documents can be represented as plain text.

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.

Parameters:
type - the non-null content type
Returns:
the editor kit

setEditorKitForContentType

public void setEditorKitForContentType(String type,
                                       EditorKit k)
Directly set the editor kit to use for the given type. A look-and-feel implementation might use this in conjunction with createEditorKitForContentType to install handlers for content types with a look-and-feel bias.
Parameters:
type - the non-null content type
k - the editor kit to be set

createEditorKitForContentType

public static EditorKit createEditorKitForContentType(String type)
Create a handler for the given type from the default registry of editor kits. The registry is created if necessary. It the registered class has not yet been loaded, an attempt is made to dynamically load the prototype of the kit for the given type. If the type was registered with a ClassLoader, that ClassLoader will be used to load the prototype. If there was no registered ClassLoader, Class.forName will be used to load the prototype.

Once a prototype EditorKit instance is successfully located, it is cloned and the clone is returned.

Parameters:
type - the content type
Returns:
the editor kit, or null if one cannot be created

registerEditorKitForContentType

public static void registerEditorKitForContentType(String type,
                                                   String classname)
Establishes the default bindings of type to name. The class will be dynamically loaded later when actually needed, and can be safely changed before attempted uses to avoid loading unwanted classes. The prototype EditorKit will be loaded with Class.forName when registered with this method.
Parameters:
type - the non-null content type
classname - the class to load later

registerEditorKitForContentType

public static void registerEditorKitForContentType(String type,
                                                   String classname,
                                                   ClassLoader loader)
Establishes the default bindings of type to name. The class will be dynamically loaded later when actually needed using the given ClassLoader, and can be safely changed before attempted uses to avoid loading unwanted classes.
Parameters:
type - the non-null content type
classname - the class to load later
loader - the ClassLoader to use to load the name

isManagingFocus

public boolean isManagingFocus()
Turns off tab traversal once focus gained.
Returns:
true, to indicate that the focus is being managed
Overrides:
isManagingFocus in class JComponent

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport.
Returns:
true if a viewport should force the Scrollables width to match its own.
Overrides:
getScrollableTracksViewportWidth in class JTextComponent

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JEditorPane. A new context is created if necessary.
Returns:
the AccessibleContext of this JEditorPane
Overrides:
getAccessibleContext in class JTextComponent

Java Platform 1.2
Beta 4

Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.