public abstract class JTextComponent extends JComponent implements Scrollable, Accessible
| Modifier and Type | Class and Description |
|---|---|
class |
JTextComponent.AccessibleJTextComponent
AccessibleJTextComponent implements accessibility hooks for
JTextComponent.
|
static class |
JTextComponent.KeyBinding |
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_KEYMAP |
static String |
FOCUS_ACCELERATOR_KEY |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JTextComponent()
Creates a new
JTextComponent instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
addCaretListener(CaretListener listener)
Adds a
CaretListener object to this text component. |
void |
addInputMethodListener(InputMethodListener listener)
Adds an
InputListener object to this text component. |
static Keymap |
addKeymap(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(CaretEvent event)
Notifies all registered
CaretListener objects that the caret
was updated. |
AccessibleContext |
getAccessibleContext()
Get the
AccessibleContext of this object. |
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. |
Color |
getCaretColor() |
CaretListener[] |
getCaretListeners()
Returns all added
CaretListener objects. |
int |
getCaretPosition()
Retrisves the current caret position.
|
Color |
getDisabledTextColor() |
Document |
getDocument() |
boolean |
getDragEnabled() |
char |
getFocusAccelerator() |
Highlighter |
getHighlighter() |
InputMethodListener[] |
getInputMethodListeners()
Returns all added
InputMethodListener objects. |
Keymap |
getKeymap()
Get the current Keymap of this component.
|
static Keymap |
getKeymap(String n)
Get a Keymap from the global keymap table, by name.
|
Insets |
getMargin() |
NavigationFilter |
getNavigationFilter() |
Dimension |
getPreferredScrollableViewportSize() |
int |
getScrollableBlockIncrement(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(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.
|
String |
getSelectedText()
Retrieves the currently selected text in this text document.
|
Color |
getSelectedTextColor() |
Color |
getSelectionColor() |
int |
getSelectionEnd()
Returns the end postion of the currently selected text.
|
int |
getSelectionStart()
Returns the start postion of the currently selected text.
|
String |
getText()
Retrieves the current text in this text document.
|
String |
getText(int offset,
int length)
Retrieves a part of the current text in this document.
|
String |
getToolTipText(MouseEvent ev)
Returns the tooltip text for this text component for the given mouse
event.
|
TextUI |
getUI()
This method returns the label's UI delegate.
|
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,
Action[] actions)
Resolves a set of bindings against a set of actions and inserts the
results into a
Keymap. |
Rectangle |
modelToView(int position) |
void |
moveCaretPosition(int position)
Moves the caret to a given position.
|
protected String |
paramString()
Returns a string representation of this JTextComponent.
|
void |
paste() |
void |
read(Reader input,
Object streamDescription)
Read and set the content this component.
|
void |
removeCaretListener(CaretListener listener)
Removed a
CaretListener object from this text component. |
void |
removeInputMethodListener(InputMethodListener listener)
Removes an
InputListener object from this text component. |
static Keymap |
removeKeymap(String n)
Remove a Keymap from the global Keymap table, by name.
|
void |
replaceSelection(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(Color newColor) |
void |
setCaretPosition(int position)
Sets the caret to a new position.
|
void |
setDisabledTextColor(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)
|
void |
setMargin(Insets m) |
void |
setNavigationFilter(NavigationFilter filter) |
void |
setSelectedTextColor(Color newColor) |
void |
setSelectionColor(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(String text) |
void |
setUI(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(Point pt) |
void |
write(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 String DEFAULT_KEYMAP
public static final String FOCUS_ACCELERATOR_KEY
public JTextComponent()
JTextComponent instance.public static Keymap getKeymap(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(String n)
n - The name of the Keymap to removeaddKeymap(java.lang.String, javax.swing.text.Keymap),
getKeymap(),
keymapspublic static Keymap addKeymap(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, 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 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 AccessibleContext getAccessibleContext()
AccessibleContext of this object.getAccessibleContext in interface AccessiblegetAccessibleContext in class JComponentAccessibleContext objectpublic String getText()
NullPointerException - if the underlaying document is nullpublic 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 String getSelectedText()
NullPointerException - if the underlaying document is nullpublic String getUIClassID()
getUIClassID in class JComponentJComponent.setUI(javax.swing.plaf.ComponentUI),
JComponent.updateUI()protected String paramString()
paramString in class JComponentpublic TextUI getUI()
public void setUI(TextUI newUI)
newUI - The label's UI delegate.public void updateUI()
updateUI in class JComponentpublic Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize in interface Scrollablepublic int getScrollableUnitIncrement(Rectangle visible, int orientation, int direction)
ScrollablegetScrollableUnitIncrement in interface 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(Rectangle visible, int orientation, int direction)
ScrollablegetScrollableBlockIncrement in interface 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 Color getCaretColor()
public void setCaretColor(Color newColor)
public Color getDisabledTextColor()
public void setDisabledTextColor(Color newColor)
public Color getSelectedTextColor()
public void setSelectedTextColor(Color newColor)
public Color getSelectionColor()
public void setSelectionColor(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(String content)
public boolean getScrollableTracksViewportHeight()
ScrollablegetScrollableTracksViewportHeight in interface Scrollablepublic boolean getScrollableTracksViewportWidth()
ScrollablegetScrollableTracksViewportWidth in interface Scrollablepublic void addCaretListener(CaretListener listener)
CaretListener object to this text component.listener - the listener to addpublic void removeCaretListener(CaretListener listener)
CaretListener object from this text component.listener - the listener to removepublic CaretListener[] getCaretListeners()
CaretListener objects.protected void fireCaretUpdate(CaretEvent event)
CaretListener objects that the caret
was updated.event - the event to sendpublic void addInputMethodListener(InputMethodListener listener)
InputListener object to this text component.addInputMethodListener in class Componentlistener - the listener to addInputMethodEvent,
Component.removeInputMethodListener(InputMethodListener),
Component.getInputMethodListeners(),
Component.getInputMethodRequests()public void removeInputMethodListener(InputMethodListener listener)
InputListener object from this text component.removeInputMethodListener in class Componentlistener - the listener to removeInputMethodEvent,
Component.addInputMethodListener(InputMethodListener),
Component.getInputMethodRequests()public InputMethodListener[] getInputMethodListeners()
InputMethodListener objects.getInputMethodListeners in class ComponentComponent.addInputMethodListener(InputMethodListener),
Component.removeInputMethodListener(InputMethodListener)public Rectangle modelToView(int position) throws BadLocationException
BadLocationExceptionpublic boolean getDragEnabled()
public void setDragEnabled(boolean enabled)
public int viewToModel(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(Reader input, Object streamDescription) throws IOException
Document.StreamDescriptionProperty.input - an input stream to read from.streamDescription - an object, describing the stream.IOException - if the reader throws it.getDocument(),
Document.getProperty(Object)public void write(Writer output) throws IOException
output - the writer to write into.IOException - if the writer throws it.public String getToolTipText(MouseEvent ev)
TextUI.getToolTipText(JTextComponent, Point).getToolTipText in class JComponentev - the mouse eventJComponent.setToolTipText(java.lang.String),
JComponent.getToolTipText()