javax.swing

Class JEditorPane

public class JEditorPane extends JTextComponent

A powerful text editor component that can handle different types of content. The JEditorPane text component is driven by an instance of {@link EditorKit}. The editor kit is responsible for providing a default {@link Document} implementation, a mechanism for loading and saving documents of its supported content type and providing a set of {@link Action}s for manipulating the content. By default the following content types are supported:
Nested Class Summary
protected classJEditorPane.AccessibleJEditorPane
Provides accessibility support for JEditorPane.
protected classJEditorPane.AccessibleJEditorPaneHTML
Provides accessibility support for JEditorPanes, when the editor kit is an instance of {@link HTMLEditorKit}.
protected classJEditorPane.JEditorPaneAccessibleHypertextSupport
This is the accessible text that is returned by {@link AccessibleJEditorPaneHTML#getAccessibleText()}.
Constructor Summary
JEditorPane()
JEditorPane(String url)
JEditorPane(String type, String text)
JEditorPane(URL url)
Method Summary
voidaddHyperlinkListener(HyperlinkListener listener)
Add a HyperlinkListener object to this editor pane.
protected EditorKitcreateDefaultEditorKit()
static EditorKitcreateEditorKitForContentType(String type)
Creates and returns an EditorKit that is appropriate for the given content type.
voidfireHyperlinkUpdate(HyperlinkEvent event)
Sends a given HyperlinkEvent to all registered listeners.
AccessibleContextgetAccessibleContext()
Returns the accessible context associated with this editor pane.
StringgetContentType()
EditorKitgetEditorKit()
Returns the EditorKit.
static StringgetEditorKitClassNameForContentType(String type)
Returns the class name of the EditorKit associated with the given content type.
EditorKitgetEditorKitForContentType(String type)
Returns the EditorKit to use for the given content type.
HyperlinkListener[]getHyperlinkListeners()
Returns all added HyperlinkListener objects.
URLgetPage()
DimensiongetPreferredSize()
Returns the preferred size for the JEditorPane.
booleangetScrollableTracksViewportHeight()
Returns true when a Viewport should force the height of this component to match the viewport height.
booleangetScrollableTracksViewportWidth()
Returns true when a Viewport should force the width of this component to match the viewport width.
protected InputStreamgetStream(URL page)
StringgetText()
StringgetUIClassID()
booleanisFocusCycleRoot()
protected StringparamString()
voidread(InputStream in, Object desc)
This method initializes from a stream.
static voidregisterEditorKitForContentType(String type, String classname)
Establishes a binding between type and classname.
static voidregisterEditorKitForContentType(String type, String classname, ClassLoader loader)
Establishes the default bindings of type to classname.
voidremoveHyperlinkListener(HyperlinkListener listener)
Removes a HyperlinkListener object to this editor pane.
voidreplaceSelection(String content)
Replaces the currently selected content with new content represented by the given string.
voidscrollToReference(String reference)
Scrolls the view to the given reference location (that is, the value returned by the UL.getRef method for the URL being displayed).
voidsetContentType(String type)
voidsetEditorKit(EditorKit newValue)
voidsetEditorKitForContentType(String type, EditorKit k)
Explicitly sets an EditorKit to be used for the given content type.
voidsetPage(String url)
Sets the current URL being displayed.
voidsetPage(URL page)
Sets the current URL being displayed.
voidsetText(String t)
Sets the text of the JEditorPane.

Constructor Detail

JEditorPane

public JEditorPane()

JEditorPane

public JEditorPane(String url)

JEditorPane

public JEditorPane(String type, String text)

JEditorPane

public JEditorPane(URL url)

Method Detail

addHyperlinkListener

public void addHyperlinkListener(HyperlinkListener listener)
Add a HyperlinkListener object to this editor pane.

Parameters: listener the listener to add

createDefaultEditorKit

protected EditorKit createDefaultEditorKit()

createEditorKitForContentType

public static EditorKit createEditorKitForContentType(String type)
Creates and returns an EditorKit that is appropriate for the given content type. This is created using the default recognized types plus any EditorKit types that have been registered.

Parameters: type the content type

Returns: an EditorKit for use with the given content type

See Also: JEditorPane JEditorPane

fireHyperlinkUpdate

public void fireHyperlinkUpdate(HyperlinkEvent event)
Sends a given HyperlinkEvent to all registered listeners.

Parameters: event the event to send

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the accessible context associated with this editor pane.

Returns: the accessible context associated with this editor pane

getContentType

public final String getContentType()

getEditorKit

public EditorKit getEditorKit()
Returns the EditorKit. If there is no EditorKit set this method calls createDefaultEditorKit() and setEditorKit() first.

getEditorKitClassNameForContentType

public static String getEditorKitClassNameForContentType(String type)
Returns the class name of the EditorKit associated with the given content type.

Parameters: type the content type

Returns: the class name of the EditorKit associated with this content type

Since: 1.3

getEditorKitForContentType

public EditorKit getEditorKitForContentType(String type)
Returns the EditorKit to use for the given content type. If an EditorKit has been explicitly set via setEditorKitForContentType then it will be returned. Otherwise an attempt will be made to create an EditorKit from the default recognzied content types or any EditorKits that have been registered. If none can be created, a PlainEditorKit is created.

Parameters: type the content type

Returns: an appropriate EditorKit for the given content type

See Also: JEditorPane JEditorPane

getHyperlinkListeners

public HyperlinkListener[] getHyperlinkListeners()
Returns all added HyperlinkListener objects.

Returns: array of listeners

Since: 1.4

getPage

public URL getPage()

getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size for the JEditorPane. This is implemented to return the super's preferred size, unless one of {@link #getScrollableTracksViewportHeight()} or {@link #getScrollableTracksViewportWidth()} returns true, in which case the preferred width and/or height is replaced by the UI's minimum size.

Returns: the preferred size for the JEditorPane

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Returns true when a Viewport should force the height of this component to match the viewport height. This is implemented to return true when the parent is an instance of JViewport and the viewport height > the UI's minimum height.

Returns: true when a Viewport should force the height of this component to match the viewport height

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Returns true when a Viewport should force the width of this component to match the viewport width. This is implemented to return true when the parent is an instance of JViewport and the viewport width > the UI's minimum width.

Returns: true when a Viewport should force the width of this component to match the viewport width

getStream

protected InputStream getStream(URL page)

getText

public String getText()

getUIClassID

public String getUIClassID()

isFocusCycleRoot

public boolean isFocusCycleRoot()

paramString

protected String paramString()

read

public void read(InputStream in, Object desc)
This method initializes from a stream.

registerEditorKitForContentType

public static void registerEditorKitForContentType(String type, String classname)
Establishes a binding between type and classname. This enables us to create an EditorKit later for the given content type.

Parameters: type the content type classname the name of the class that is associated with this content type

registerEditorKitForContentType

public static void registerEditorKitForContentType(String type, String classname, ClassLoader loader)
Establishes the default bindings of type to classname.

removeHyperlinkListener

public void removeHyperlinkListener(HyperlinkListener listener)
Removes a HyperlinkListener object to this editor pane.

Parameters: listener the listener to remove

replaceSelection

public void replaceSelection(String content)
Replaces the currently selected content with new content represented by the given string.

scrollToReference

public void scrollToReference(String reference)
Scrolls the view to the given reference location (that is, the value returned by the UL.getRef method for the URL being displayed).

setContentType

public final void setContentType(String type)

setEditorKit

public void setEditorKit(EditorKit newValue)

setEditorKitForContentType

public void setEditorKitForContentType(String type, EditorKit k)
Explicitly sets an EditorKit to be used for the given content type.

Parameters: type the content type k the EditorKit to use for the given content type

setPage

public void setPage(String url)
Sets the current URL being displayed.

setPage

public void setPage(URL page)
Sets the current URL being displayed.

setText

public void setText(String t)
Sets the text of the JEditorPane. The argument t is expected to be in the format of the current EditorKit. This removes the content of the current document and uses the EditorKit to read in the new text. This allows the EditorKit to handle the String rather than just inserting in plain text.

Parameters: t the text to display in this JEditorPane