public abstract class JTextComponent extends javax.swing.JComponent implements javax.swing.Scrollable, javax.accessibility.Accessible
| Modifier and Type | Class and Description |
|---|---|
class |
JTextComponent.AccessibleJTextComponent
AccessibleJTextComponent implements accessibility hooks for
JTextComponent.
|
static class |
JTextComponent.KeyBinding |
javax.swing.JComponent.AccessibleJComponent| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_KEYMAP |
static java.lang.String |
FOCUS_ACCELERATOR_KEY |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW| Constructor and Description |
|---|
JTextComponent()
Creates a new
JTextComponent instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
addCaretListener(javax.swing.event.CaretListener listener)
Adds a
CaretListener object to this text component. |
void |
addInputMethodListener(java.awt.event.InputMethodListener listener)
Adds an
InputListener object to this text component. |
static Keymap |
addKeymap(java.lang.String n,
Keymap parent)
Create a new Keymap with a specific name and parent, and add the new
Keymap to the global keymap table.
|
void |
copy() |
void |
cut() |
protected void |
fireCaretUpdate(javax.swing.event.CaretEvent event)
Notifies all registered
CaretListener objects that the caret
was updated. |
javax.accessibility.AccessibleContext |
getAccessibleContext()
Get the
AccessibleContext of this object. |
javax.swing.Action[] |
getActions()
Returns the set of available Actions this component's associated
editor can run.
|
Caret |
getCaret()
The
Caret object used in this text component. |
java.awt.Color |
getCaretColor() |
javax.swing.event.CaretListener[] |
getCaretListeners()
Returns all added
CaretListener objects. |
int |
getCaretPosition()
Retrisves the current caret position.
|
java.awt.Color |
getDisabledTextColor() |
Document |
getDocument() |
boolean |
getDragEnabled() |
char |
getFocusAccelerator() |
Highlighter |
getHighlighter() |
java.awt.event.InputMethodListener[] |
getInputMethodListeners()
Returns all added
InputMethodListener objects. |
Keymap |
getKeymap()
Get the current Keymap of this component.
|
static Keymap |
getKeymap(java.lang.String n)
Get a Keymap from the global keymap table, by name.
|
java.awt.Insets |
getMargin() |
NavigationFilter |
getNavigationFilter() |
java.awt.Dimension |
getPreferredScrollableViewportSize() |
int |
getScrollableBlockIncrement(java.awt.Rectangle visible,
int orientation,
int direction)
Return the preferred scrolling amount (in pixels) for the given
scrolling direction and orientation when scrolling in large amounts
(pages).
|
boolean |
getScrollableTracksViewportHeight()
Return true if the height of the scrollable is always equal to the view,
where it is displayed, height.In such case, the vertical scrolling should
not be performed.
|
boolean |
getScrollableTracksViewportWidth()
Return true if the width of the scrollable is always equal to the
view, where it is displayed, width (for instance, the text area with
the word wrap).
|
int |
getScrollableUnitIncrement(java.awt.Rectangle visible,
int orientation,
int direction)
Return the preferred scrolling amount (in pixels) for the given
scrolling direction and orientation when scrolling in small amounts
like table lines.
|
java.lang.String |
getSelectedText()
Retrieves the currently selected text in this text document.
|
java.awt.Color |
getSelectedTextColor() |
java.awt.Color |
getSelectionColor() |
int |
getSelectionEnd()
Returns the end postion of the currently selected text.
|
int |
getSelectionStart()
Returns the start postion of the currently selected text.
|
java.lang.String |
getText()
Retrieves the current text in this text document.
|
java.lang.String |
getText(int offset,
int length)
Retrieves a part of the current text in this document.
|
java.lang.String |
getToolTipText(java.awt.event.MouseEvent ev)
Returns the tooltip text for this text component for the given mouse
event.
|
javax.swing.plaf.TextUI |
getUI()
This method returns the label's UI delegate.
|
java.lang.String |
getUIClassID()
Returns a string that specifies the name of the Look and Feel class
that renders this component.
|
boolean |
isEditable()
Checks whether this text component it editable.
|
static void |
loadKeymap(Keymap map,
JTextComponent.KeyBinding[] bindings,
javax.swing.Action[] actions)
Resolves a set of bindings against a set of actions and inserts the
results into a
Keymap. |
java.awt.Rectangle |
modelToView(int position) |
void |
moveCaretPosition(int position)
Moves the caret to a given position.
|
protected java.lang.String |
paramString()
Returns a string representation of this JTextComponent.
|
void |
paste() |
void |
read(java.io.Reader input,
java.lang.Object streamDescription)
Read and set the content this component.
|
void |
removeCaretListener(javax.swing.event.CaretListener listener)
Removed a
CaretListener object from this text component. |
void |
removeInputMethodListener(java.awt.event.InputMethodListener listener)
Removes an
InputListener object from this text component. |
static Keymap |
removeKeymap(java.lang.String n)
Remove a Keymap from the global Keymap table, by name.
|
void |
replaceSelection(java.lang.String content) |
void |
select(int start,
int end)
Selects a part of the content of the text component.
|
void |
selectAll()
Selects the whole content of the text component.
|
void |
setCaret(Caret newCaret)
Sets a new
Caret for this text component. |
void |
setCaretColor(java.awt.Color newColor) |
void |
setCaretPosition(int position)
Sets the caret to a new position.
|
void |
setDisabledTextColor(java.awt.Color newColor) |
void |
setDocument(Document newDoc) |
void |
setDragEnabled(boolean enabled) |
void |
setEditable(boolean newValue)
Enables/disabled this text component's editability.
|
void |
setFocusAccelerator(char newKey) |
void |
setHighlighter(Highlighter newHighlighter) |
void |
setKeymap(Keymap k)
Set the current Keymap of this component, installing appropriate
KeymapWrapper and KeymapActionMap objects in the
InputMap and ActionMap parent chains, respectively,
and fire a property change event with name "keymap". |
void |
setMargin(java.awt.Insets m) |
void |
setNavigationFilter(NavigationFilter filter) |
void |
setSelectedTextColor(java.awt.Color newColor) |
void |
setSelectionColor(java.awt.Color newColor) |
void |
setSelectionEnd(int end)
Selects the text from the selection start postion to the given position.
|
void |
setSelectionStart(int start)
Selects the text from the given postion to the selection end position.
|
void |
setText(java.lang.String text) |
void |
setUI(javax.swing.plaf.TextUI newUI)
This method sets the label's UI delegate.
|
void |
updateUI()
This method resets the label's UI delegate to the default UI for the
current look and feel.
|
int |
viewToModel(java.awt.Point pt) |
void |
write(java.io.Writer output)
Write the content of this component to the given stream.
|
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, getPreferredSize, 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, 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, setFocusTraversalKeys, 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, 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, transferFocusUpCyclepublic static final java.lang.String DEFAULT_KEYMAP
public static final java.lang.String FOCUS_ACCELERATOR_KEY
public JTextComponent()
JTextComponent instance.public static Keymap getKeymap(java.lang.String n)
n - The name of the Keymap to look upnull if no such Keymap existsaddKeymap(java.lang.String, javax.swing.text.Keymap),
removeKeymap(java.lang.String),
keymapspublic static Keymap removeKeymap(java.lang.String n)
n - The name of the Keymap to removeaddKeymap(java.lang.String, javax.swing.text.Keymap),
getKeymap(),
keymapspublic static Keymap addKeymap(java.lang.String n, Keymap parent)
null,
in which case the new Keymap will not be added to the global
Keymap table. The parent may also be null, which is
harmless.n - The name of the new Keymap, or nullparent - The parent of the new Keymap, or nullremoveKeymap(java.lang.String),
getKeymap(),
keymapspublic Keymap getKeymap()
setKeymap(javax.swing.text.Keymap),
keymappublic void setKeymap(Keymap k)
KeymapWrapper and KeymapActionMap objects in the
InputMap and ActionMap parent chains, respectively,
and fire a property change event with name "keymap".getKeymap(),
keymappublic static void loadKeymap(Keymap map, JTextComponent.KeyBinding[] bindings, javax.swing.Action[] actions)
Keymap. Specifically, for each provided binding
b, if there exists a provided action a such
that a.getValue(Action.NAME) == b.ActionName then an
entry is added to the Keymap mapping b to
a.map - The Keymap to add new mappings tobindings - The set of bindings to add to the Keymapactions - The set of actions to resolve binding names againstAction.NAME,
Action.getValue(java.lang.String),
JTextComponent.KeyBinding.actionNamepublic javax.swing.Action[] getActions()
getUI().getEditorKit().getActions(). This set of Actions
is a reasonable value to provide as a parameter to loadKeymap(javax.swing.text.Keymap, javax.swing.text.JTextComponent.KeyBinding[], javax.swing.Action[]), when resolving a set of JTextComponent.KeyBinding objects
against this component.EditorKitTextUI.getEditorKit(javax.swing.text.JTextComponent),
EditorKit.getActions()public void setDocument(Document newDoc)
public Document getDocument()
public javax.accessibility.AccessibleContext getAccessibleContext()
AccessibleContext of this object.getAccessibleContext in interface javax.accessibility.AccessiblegetAccessibleContext in class javax.swing.JComponentAccessibleContext objectpublic void setMargin(java.awt.Insets m)
public java.awt.Insets getMargin()
public void setText(java.lang.String text)
public java.lang.String getText()
java.lang.NullPointerException - if the underlaying document is nullpublic java.lang.String getText(int offset, int length) throws BadLocationException
offset - the postion of the first characterlength - the length of the text to retrieveBadLocationException - if arguments do not hold pre-conditionspublic java.lang.String getSelectedText()
java.lang.NullPointerException - if the underlaying document is nullpublic java.lang.String getUIClassID()
getUIClassID in class javax.swing.JComponentJComponent.setUI(javax.swing.plaf.ComponentUI),
JComponent.updateUI()protected java.lang.String paramString()
paramString in class javax.swing.JComponentpublic javax.swing.plaf.TextUI getUI()
public void setUI(javax.swing.plaf.TextUI newUI)
newUI - The label's UI delegate.public void updateUI()
updateUI in class javax.swing.JComponentpublic java.awt.Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize in interface javax.swing.Scrollablepublic int getScrollableUnitIncrement(java.awt.Rectangle visible, int orientation, int direction)
javax.swing.ScrollablegetScrollableUnitIncrement in interface javax.swing.Scrollablevisible - the currently visible part of the component.orientation - the scrolling orientationdirection - the scrolling direction (negative - up, positive -down).
The values greater than one means that more mouse wheel or similar
events were generated, and hence it is better to scroll the longer
distance.public int getScrollableBlockIncrement(java.awt.Rectangle visible, int orientation, int direction)
javax.swing.ScrollablegetScrollableBlockIncrement in interface javax.swing.Scrollablevisible - the currently visible part of the component.orientation - the scrolling orientationdirection - the scrolling direction (negative - up, positive -down).
The values greater than one means that more mouse wheel or similar
events were generated, and hence it is better to scroll the longer
distance.public boolean isEditable()
public void setEditable(boolean newValue)
newValue - true to make it editable, false otherwise.public Caret getCaret()
Caret object used in this text component.public void setCaret(Caret newCaret)
Caret for this text component.newCaret - the new Caret to setpublic java.awt.Color getCaretColor()
public void setCaretColor(java.awt.Color newColor)
public java.awt.Color getDisabledTextColor()
public void setDisabledTextColor(java.awt.Color newColor)
public java.awt.Color getSelectedTextColor()
public void setSelectedTextColor(java.awt.Color newColor)
public java.awt.Color getSelectionColor()
public void setSelectionColor(java.awt.Color newColor)
public int getCaretPosition()
public void setCaretPosition(int position)
position - the new positionpublic void moveCaretPosition(int position)
public Highlighter getHighlighter()
public void setHighlighter(Highlighter newHighlighter)
public int getSelectionStart()
public void setSelectionStart(int start)
start - the start positon of the selected text.public int getSelectionEnd()
public void setSelectionEnd(int end)
end - the end positon of the selected text.public void select(int start, int end)
start - the start position of the selected textend - the end position of the selected textpublic void selectAll()
public void replaceSelection(java.lang.String content)
public boolean getScrollableTracksViewportHeight()
javax.swing.ScrollablegetScrollableTracksViewportHeight in interface javax.swing.Scrollablepublic boolean getScrollableTracksViewportWidth()
javax.swing.ScrollablegetScrollableTracksViewportWidth in interface javax.swing.Scrollablepublic void addCaretListener(javax.swing.event.CaretListener listener)
CaretListener object to this text component.listener - the listener to addpublic void removeCaretListener(javax.swing.event.CaretListener listener)
CaretListener object from this text component.listener - the listener to removepublic javax.swing.event.CaretListener[] getCaretListeners()
CaretListener objects.protected void fireCaretUpdate(javax.swing.event.CaretEvent event)
CaretListener objects that the caret
was updated.event - the event to sendpublic void addInputMethodListener(java.awt.event.InputMethodListener listener)
InputListener object to this text component.addInputMethodListener in class java.awt.Componentlistener - the listener to addInputMethodEvent,
Component.removeInputMethodListener(InputMethodListener),
Component.getInputMethodListeners(),
Component.getInputMethodRequests()public void removeInputMethodListener(java.awt.event.InputMethodListener listener)
InputListener object from this text component.removeInputMethodListener in class java.awt.Componentlistener - the listener to removeInputMethodEvent,
Component.addInputMethodListener(InputMethodListener),
Component.getInputMethodRequests()public java.awt.event.InputMethodListener[] getInputMethodListeners()
InputMethodListener objects.getInputMethodListeners in class java.awt.ComponentComponent.addInputMethodListener(InputMethodListener),
Component.removeInputMethodListener(InputMethodListener)public java.awt.Rectangle modelToView(int position) throws BadLocationException
BadLocationExceptionpublic boolean getDragEnabled()
public void setDragEnabled(boolean enabled)
public int viewToModel(java.awt.Point pt)
public void copy()
public void cut()
public void paste()
public void setFocusAccelerator(char newKey)
public char getFocusAccelerator()
public NavigationFilter getNavigationFilter()
public void setNavigationFilter(NavigationFilter filter)
public void read(java.io.Reader input, java.lang.Object streamDescription) throws java.io.IOException
Document.StreamDescriptionProperty.input - an input stream to read from.streamDescription - an object, describing the stream.java.io.IOException - if the reader throws it.getDocument(),
Document.getProperty(Object)public void write(java.io.Writer output) throws java.io.IOException
output - the writer to write into.java.io.IOException - if the writer throws it.public java.lang.String getToolTipText(java.awt.event.MouseEvent ev)
TextUI.getToolTipText(JTextComponent, Point).getToolTipText in class javax.swing.JComponentev - the mouse eventJComponent.setToolTipText(java.lang.String),
JComponent.getToolTipText()