public class JTextPane extends JEditorPane
This component models paragraphs that are composed of runs of character level attributes. Each paragraph may have a logical style attached to it which contains the default attributes to use if not overridden by attributes set on the paragraph or character run. Components and images may be embedded in the flow of text.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
StyledEditorKit
JEditorPane.AccessibleJEditorPane , JEditorPane.AccessibleJEditorPaneHTML , JEditorPane.JEditorPaneAccessibleHypertextSupport JTextComponent.AccessibleJTextComponent , JTextComponent.DropLocation , JTextComponent.KeyBinding JComponent.AccessibleJComponent Container.AccessibleAWTContainer Component.AccessibleAWTComponent , Component.BaselineResizeBehavior , Component.BltBufferStrategy , Component.FlipBufferStrategy HONOR_DISPLAY_PROPERTIES, W3C_LENGTH_UNITSDEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JTextPane()
Creates a new
JTextPane.
|
JTextPane(StyledDocument
Creates a new
JTextPane, with a specified document model.
|
| Modifier and Type | Method and Description |
|---|---|
Style |
addStyle(String
Adds a new style into the logical style hierarchy.
|
protected EditorKit |
createDefaultEditorKit()
Creates the
EditorKit to use by default.
|
AttributeSet |
getCharacterAttributes()
Fetches the character attributes in effect at the current location of the caret, or
null.
|
MutableAttributeSet |
getInputAttributes()
Gets the input attributes for the pane.
|
Style |
getLogicalStyle()
Fetches the logical style assigned to the paragraph represented by the current position of the caret, or
null.
|
AttributeSet |
getParagraphAttributes()
Fetches the current paragraph attributes in effect at the location of the caret, or
null if none.
|
Style |
getStyle(String
Fetches a named non-
null style previously added.
|
StyledDocument |
getStyledDocument()
Fetches the model associated with the editor.
|
protected StyledEditorKit |
getStyledEditorKit()
Gets the editor kit.
|
String |
getUIClassID()
Returns the class ID for the UI.
|
void |
insertComponent(Component
Inserts a component into the document as a replacement for the currently selected content.
|
void |
insertIcon(Icon
Inserts an icon into the document as a replacement for the currently selected content.
|
protected String |
paramString()
Returns a string representation of this
JTextPane.
|
void |
removeStyle(String
Removes a named non-
null style previously added to the document.
|
void |
replaceSelection(String
Replaces the currently selected content with new content represented by the given string.
|
void |
setCharacterAttributes(AttributeSet
Applies the given attributes to character content.
|
void |
setDocument(Document
Associates the editor with a text document.
|
void |
setEditorKit(EditorKit
Sets the currently installed kit for handling content.
|
void |
setLogicalStyle(Style
Sets the logical style to use for the paragraph at the current caret position.
|
void |
setParagraphAttributes(AttributeSet
Applies the given attributes to paragraphs.
|
void |
setStyledDocument(StyledDocument
Associates the editor with a text document.
|
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setTextaddCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, writeaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic JTextPane()
JTextPane. A new instance of
StyledEditorKit is created and set, and the document model set to
null.
public JTextPane(StyledDocumentdoc)
JTextPane, with a specified document model. A new instance of
javax.swing.text.StyledEditorKit is created and set.
doc - the document model
public StringgetUIClassID()
getUIClassID in class
JEditorPane
JComponent.getUIClassID() ,
UIDefaults.getUI(javax.swing.JComponent)
public void setDocument(Documentdoc)
StyledDocument.
setDocument in class
JTextComponent
doc - the document to display/edit
IllegalArgumentException - if
doc can't be narrowed to a
StyledDocument which is the required type of model for this text component
JTextComponent.getDocument()
public void setStyledDocument(StyledDocumentdoc)
doc - the document to display/edit
public StyledDocumentgetStyledDocument()
public void replaceSelection(Stringcontent)
replaceSelection in class
JEditorPane
content - the content to replace the selection with
public void insertComponent(Componentc)
The component given is the actual component used by the JTextPane. Since components cannot be a child of more than one container, this method should not be used in situations where the model is shared by text components.
The component is placed relative to the text baseline according to the value returned by Component.getAlignmentY. For Swing components this value can be conveniently set using the method JComponent.setAlignmentY. For example, setting a value of 0.75 will cause 75 percent of the component to be above the baseline, and 25 percent of the component to be below the baseline.
c - the component to insert
public void insertIcon(Icong)
g - the icon to insert
Icon
public StyleaddStyle(String nm, Style parent)
nm - the name of the style (must be unique within the collection of named styles). The name may be
null if the style is unnamed, but the caller is responsible for managing the reference returned as an unnamed style can't be fetched by name. An unnamed style may be useful for things like character attribute overrides such as found in a style run.
parent - the parent style. This may be
null if unspecified attributes need not be resolved in some other style.
Style
public void removeStyle(Stringnm)
null style previously added to the document.
nm - the name of the style to remove
public StylegetStyle(String nm)
null style previously added.
nm - the name of the style
Style
public void setLogicalStyle(Styles)
s - the logical style to assign to the paragraph, or
null for no style
public StylegetLogicalStyle()
null.
Style
public AttributeSetgetCharacterAttributes()
null.
null
public void setCharacterAttributes(AttributeSetattr, boolean replace)
attr - the attributes
replace - if true, then replace the existing attributes first
public AttributeSetgetParagraphAttributes()
null if none.
public void setParagraphAttributes(AttributeSetattr, boolean replace)
attr - the non-
null attributes
replace - if true, replace the existing attributes first
public MutableAttributeSetgetInputAttributes()
protected final StyledEditorKitgetStyledEditorKit()
protected EditorKitcreateDefaultEditorKit()
EditorKit to use by default. This is implemented to return
javax.swing.text.StyledEditorKit.
createDefaultEditorKit in class
JEditorPane
public final void setEditorKit(EditorKitkit)
setEditorKit in class
JEditorPane
kit - the desired editor behavior
IllegalArgumentException - if kit is not a
StyledEditorKit
JEditorPane.getEditorKit()
protected StringparamString()
JTextPane. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be
null.
paramString in class
JEditorPane
JTextPane