public class JTextPane extends JEditorPane
StyledDocument
content model and a StyledEditorKit
.JEditorPane.AccessibleJEditorPane, JEditorPane.AccessibleJEditorPaneHTML, JEditorPane.JEditorPaneAccessibleHypertextSupport
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBinding
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JTextPane()
Creates a new
JTextPane with a null document. |
JTextPane(StyledDocument document)
Creates a new
JTextPane and sets the specified
document . |
Modifier and Type | Method and Description |
---|---|
Style |
addStyle(String nm,
Style parent)
Adds a style into the style hierarchy.
|
protected EditorKit |
createDefaultEditorKit()
Creates the default
EditorKit that is used in
JTextPane s. |
AttributeSet |
getCharacterAttributes()
Returns the text attributes for the character at the current caret
position.
|
MutableAttributeSet |
getInputAttributes()
Returns the attributes that are applied to newly inserted text.
|
Style |
getLogicalStyle()
Returns the logical style of the paragraph at the current caret position.
|
AttributeSet |
getParagraphAttributes()
Returns the text attributes of the paragraph at the current caret
position.
|
Style |
getStyle(String nm)
Looks up and returns a named
Style . |
StyledDocument |
getStyledDocument()
Returns the
StyledDocument that is the content model for
this JTextPane . |
protected StyledEditorKit |
getStyledEditorKit()
Returns the
StyledEditorKit that is currently used by this
JTextPane . |
String |
getUIClassID()
Returns the UI class ID.
|
void |
insertComponent(Component component)
Inserts an AWT or Swing component into the text at the current caret
position.
|
void |
insertIcon(Icon icon)
Inserts an
Icon into the text at the current caret position. |
protected String |
paramString()
Returns a param string that can be used for debugging.
|
void |
removeStyle(String nm)
Removes a named
Style from the style hierarchy. |
void |
replaceSelection(String content)
Replaces the currently selected text with the specified
content . |
void |
setCharacterAttributes(AttributeSet attribute,
boolean replace)
Sets text attributes for the current selection.
|
void |
setDocument(Document document)
Sets the content model for this
JTextPane . |
void |
setEditorKit(EditorKit editor)
Sets the
EditorKit to use for this JTextPane . |
void |
setLogicalStyle(Style style)
Sets the logical style for the paragraph at the current caret position.
|
void |
setParagraphAttributes(AttributeSet attribute,
boolean replace)
Sets text attributes for the paragraph at the current selection.
|
void |
setStyledDocument(StyledDocument document)
Sets the content model for this
JTextPane . |
addHyperlinkListener, createEditorKitForContentType, fireHyperlinkUpdate, getAccessibleContext, getContentType, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getHyperlinkListeners, getPage, getPreferredSize, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getStream, getText, isFocusCycleRoot, read, registerEditorKitForContentType, registerEditorKitForContentType, removeHyperlinkListener, scrollToReference, setContentType, setEditorKitForContentType, setPage, setPage, setText
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodListeners, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, read, removeCaretListener, removeInputMethodListener, removeKeymap, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, 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, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, 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, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public JTextPane()
JTextPane
with a null
document.public JTextPane(StyledDocument document)
JTextPane
and sets the specified
document
.document
- the content model to usepublic String getUIClassID()
TextPaneUI
.getUIClassID
in class JEditorPane
TextPaneUI
JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
public void setDocument(Document document)
JTextPane
.
JTextPane
can only be used with StyledDocument
s,
if you try to set a different type of Document
, an
IllegalArgumentException
is thrown.setDocument
in class JTextComponent
document
- the content model to setIllegalArgumentException
- if document
is not an
instance of StyledDocument
setStyledDocument(javax.swing.text.StyledDocument)
public StyledDocument getStyledDocument()
StyledDocument
that is the content model for
this JTextPane
. This is a typed wrapper for
JTextComponent.getDocument()
.JTextPane
public void setStyledDocument(StyledDocument document)
JTextPane
.document
- the content model to setpublic void replaceSelection(String content)
content
. If there is no selected text, this results
in a simple insertion at the current caret position. If there is
no content
specified, this results in the selection
beeing deleted.replaceSelection
in class JEditorPane
content
- the text with which the selection is replacedpublic void insertComponent(Component component)
component
- the component to be insertedpublic void insertIcon(Icon icon)
Icon
into the text at the current caret position.icon
- the Icon
to be insertedpublic Style addStyle(String nm, Style parent)
parent
style, if one is specified.
While it is legal to add nameless styles (nm == null
nm
- the name of the style or null
if the style should
be unnamedparent
- the parent in which unspecified style attributes are
resolved, or null
if that is not necessaryStyle
public void removeStyle(String nm)
Style
from the style hierarchy.nm
- the name of the Style
to be removedpublic Style getStyle(String nm)
Style
.nm
- the name of the Style
Style
of null
if no such
Style
existspublic Style getLogicalStyle()
public void setLogicalStyle(Style style)
style
- the style to set for the current paragraphpublic AttributeSet getCharacterAttributes()
public void setCharacterAttributes(AttributeSet attribute, boolean replace)
attribute
- the text attributes to setreplace
- if true
, the attributes of the current
selection are overridden, otherwise they are mergedgetInputAttributes()
public AttributeSet getParagraphAttributes()
public void setParagraphAttributes(AttributeSet attribute, boolean replace)
attribute
- the text attributes to setreplace
- if true
, the attributes of the current
selection are overridden, otherwise they are mergedpublic MutableAttributeSet getInputAttributes()
MutableAttributeSet
, so you can easily modify these
attributes.protected final StyledEditorKit getStyledEditorKit()
StyledEditorKit
that is currently used by this
JTextPane
.StyledEditorKit
of this
JTextPane
protected EditorKit createDefaultEditorKit()
createDefaultEditorKit
in class JEditorPane
EditorKit
that is used in
JTextPane
spublic final void setEditorKit(EditorKit editor)
EditorKit
to use for this JTextPane
.
JTextPane
s can only handle StyledEditorKit
s,
if client programs try to set a different type of EditorKit
then an IllegalArgumentException is thrownsetEditorKit
in class JEditorPane
editor
- the EditorKit
to setIllegalArgumentException
- if editor
is no
StyledEditorKit
protected String paramString()
paramString
in class JEditorPane