Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
public class JEditorPane
extends JTextComponent
EditorKit
. The editor kit is responsible for providing
a default Document
implementation, a mechanism for loading
and saving documents of its supported content type and providing
a set of Action
s for manipulating the content.
By default the following content types are supported:
text/plain
: Plain text, handled by
DefaultEditorKit
.text/html
: HTML 4.0 styled text, handled by
HTMLEditorKit
.text/rtf
: RTF text, handled by
RTFEditorKit
.Nested Class Summary | |
protected class |
|
protected class |
|
protected class |
|
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent | |
JTextComponent.AccessibleJTextComponent , JTextComponent.KeyBinding |
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 , Component.BltBufferStrategy , Component.FlipBufferStrategy |
Field Summary |
Fields inherited from class javax.swing.text.JTextComponent | |
DEFAULT_KEYMAP , FOCUS_ACCELERATOR_KEY |
Fields inherited from class javax.swing.JComponent | |
TOOL_TIP_TEXT_KEY , UNDEFINED_CONDITION , WHEN_ANCESTOR_OF_FOCUSED_COMPONENT , WHEN_FOCUSED , WHEN_IN_FOCUSED_WINDOW , accessibleContext , listenerList , ui |
Fields inherited from class java.awt.Component | |
BOTTOM_ALIGNMENT , CENTER_ALIGNMENT , LEFT_ALIGNMENT , RIGHT_ALIGNMENT , TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver | |
ABORT , ALLBITS , ERROR , FRAMEBITS , HEIGHT , PROPERTIES , SOMEBITS , WIDTH |
Constructor Summary | |
| |
| |
| |
|
Method Summary | |
void |
|
protected EditorKit | |
static EditorKit |
|
void |
|
AccessibleContext |
|
String | |
EditorKit |
|
static String |
|
EditorKit |
|
HyperlinkListener[] |
|
URL |
|
Dimension |
|
boolean |
|
boolean |
|
protected InputStream | |
String |
|
String |
|
boolean |
|
protected String |
|
void |
|
static void |
|
static void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void | |
void | |
void |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public void addHyperlinkListener(HyperlinkListener listener)
Add aHyperlinkListener
object to this editor pane.
- Parameters:
listener
- the listener to add
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
public void fireHyperlinkUpdate(HyperlinkEvent event)
Sends a givenHyperlinkEvent
to all registered listeners.
- Parameters:
event
- the event to send
public AccessibleContext getAccessibleContext()
Returns the accessible context associated with this editor pane.
- Specified by:
- getAccessibleContext in interface Accessible
- Overrides:
- getAccessibleContext in interface JTextComponent
- Returns:
- the accessible context associated with this editor pane
public EditorKit getEditorKit()
Returns the EditorKit. If there is no EditorKit set this method calls createDefaultEditorKit() and setEditorKit() first.
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
public EditorKit getEditorKitForContentType(String type)
Returns the EditorKit to use for the given content type. If an EditorKit has been explicitly set viasetEditorKitForContentType
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
public HyperlinkListener[] getHyperlinkListeners()
Returns all addedHyperlinkListener
objects.
- Returns:
- array of listeners
- Since:
- 1.4
public Dimension getPreferredSize()
Returns the preferred size for the JEditorPane. This is implemented to return the super's preferred size, unless one ofgetScrollableTracksViewportHeight()
orgetScrollableTracksViewportWidth()
returnstrue
, in which case the preferred width and/or height is replaced by the UI's minimum size.
- Overrides:
- getPreferredSize in interface JComponent
- Returns:
- the preferred size for the JEditorPane
public boolean getScrollableTracksViewportHeight()
Returnstrue
when a Viewport should force the height of this component to match the viewport height. This is implemented to returntrue
when the parent is an instance of JViewport and the viewport height > the UI's minimum height.
- Specified by:
- getScrollableTracksViewportHeight in interface Scrollable
- Overrides:
- getScrollableTracksViewportHeight in interface JTextComponent
- Returns:
true
when a Viewport should force the height of this component to match the viewport height
public boolean getScrollableTracksViewportWidth()
Returnstrue
when a Viewport should force the width of this component to match the viewport width. This is implemented to returntrue
when the parent is an instance of JViewport and the viewport width > the UI's minimum width.
- Specified by:
- getScrollableTracksViewportWidth in interface Scrollable
- Overrides:
- getScrollableTracksViewportWidth in interface JTextComponent
- Returns:
true
when a Viewport should force the width of this component to match the viewport width
public String getText()
Retrieves the current text in this text document.
- Overrides:
- getText in interface JTextComponent
- Returns:
- the text
- Throws:
NullPointerException
- if the underlaying document is null
public String getUIClassID()
Returns a string that specifies the name of the Look and Feel class that renders this component.
- Overrides:
- getUIClassID in interface JTextComponent
- Returns:
- the string "TextComponentUI"
public boolean isFocusCycleRoot()
Check whether this Container is a focus cycle root.
- Overrides:
- isFocusCycleRoot in interface Container
- Returns:
- true if this is a focus cycle root, false otherwise
- Since:
- 1.4
protected String paramString()
Returns a string representation of this JTextComponent.
- Overrides:
- paramString in interface JTextComponent
public void read(InputStream in, Object desc) throws IOException
This method initializes from a stream.
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 typeclassname
- the name of the class that is associated with this content type
public static void registerEditorKitForContentType(String type, String classname, ClassLoader loader)
Establishes the default bindings of type to classname.
public void removeHyperlinkListener(HyperlinkListener listener)
Removes aHyperlinkListener
object to this editor pane.
- Parameters:
listener
- the listener to remove
public void replaceSelection(String content)
Replaces the currently selected content with new content represented by the given string.
- Overrides:
- replaceSelection in interface JTextComponent
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).
public void setEditorKitForContentType(String type, EditorKit k)
Explicitly sets an EditorKit to be used for the given content type.
- Parameters:
type
- the content typek
- the EditorKit to use for the given content type
public void setText(String t)
Sets the text of the JEditorPane. The argumentt
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.
- Overrides:
- setText in interface JTextComponent
- Parameters:
t
- the text to display in this JEditorPane