public class JTextField extends JTextComponent implements SwingConstants
| Modifier and Type | Class and Description |
|---|---|
protected class |
JTextField.AccessibleJTextField
AccessibleJTextField
|
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBindingJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static String |
notifyAction
Name of the action that gets sent when the content of the text field
gets accepted.
|
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYaccessibleContext, 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_ALIGNMENTBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WESTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JTextField()
Creates a new instance of
JTextField. |
JTextField(Document doc,
String text,
int columns)
Creates a new instance of
JTextField. |
JTextField(int columns)
Creates a new instance of
JTextField. |
JTextField(String text)
Creates a new instance of
JTextField. |
JTextField(String text,
int columns)
Creates a new instance of
JTextField. |
| Modifier and Type | Method and Description |
|---|---|
void |
addActionListener(ActionListener listener)
Adds a new listener object to this text field.
|
protected void |
configurePropertiesFromAction(Action action) |
protected PropertyChangeListener |
createActionPropertyChangeListener(Action action) |
protected Document |
createDefaultModel()
Creates the default model for this text field.
|
protected void |
fireActionPerformed()
Sends an action event to all registered
ActionListener objects. |
AccessibleContext |
getAccessibleContext()
Returns the accessible context associated with the
JTextField. |
Action |
getAction() |
ActionListener[] |
getActionListeners()
Returns all registered
ActionListener objects. |
Action[] |
getActions()
Returns the set of Actions that are commands for the editor.
|
int |
getColumns()
Returns the number of columns of this text field.
|
protected int |
getColumnWidth()
Returns the column width, which is the width of the character m
for the font in use.
|
int |
getHorizontalAlignment()
Returns the horizontal alignment, which is one of: JTextField.LEFT,
JTextField.CENTER, JTextField.RIGHT, JTextField.LEADING,
JTextField.TRAILING.
|
BoundedRangeModel |
getHorizontalVisibility()
Returns the bounded range model that describes the horizontal visibility
of the text field in the case when the text does not fit into the
available space.
|
Dimension |
getPreferredSize()
Returns the preferred size.
|
int |
getScrollOffset()
Returns the scroll offset in pixels.
|
String |
getUIClassID()
Returns the class ID for the UI.
|
boolean |
isValidateRoot()
Returns
true, unless this is embedded in a
JViewport in which case the viewport takes responsibility of
validating. |
void |
postActionEvent() |
void |
removeActionListener(ActionListener listener)
Removes a listener object from this text field.
|
void |
scrollRectToVisible(Rectangle r)
Calls
scrollRectToVisible on the component's parent. |
void |
setAction(Action newAction) |
void |
setActionCommand(String command)
Sets the command string used in action events.
|
void |
setColumns(int columns)
Sets the number of columns and then invalidates the layout.
|
void |
setDocument(Document doc)
Sets the document to be used for this JTextField.
|
void |
setFont(Font newFont)
Sets the current font and revalidates so the font will take effect.
|
void |
setHorizontalAlignment(int newAlign)
Sets the horizontal alignment of the text.
|
void |
setScrollOffset(int offset)
Sets the scroll offset in pixels.
|
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getFocusAccelerator, getHighlighter, getInputMethodListeners, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paramString, paste, read, removeCaretListener, removeInputMethodListener, removeKeymap, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setDisabledTextColor, setDragEnabled, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, writeaddAncestorListener, 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, 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, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, 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 notifyAction
public JTextField()
JTextField.public JTextField(String text)
JTextField.text - the initial textpublic JTextField(int columns)
JTextField.columns - the number of columnsIllegalArgumentException - if columns %lt; 0public JTextField(String text, int columns)
JTextField.text - the initial textcolumns - the number of columnsIllegalArgumentException - if columns %lt; 0public JTextField(Document doc, String text, int columns)
JTextField.doc - the document to usetext - the initial textcolumns - the number of columnsIllegalArgumentException - if columns %lt; 0protected Document createDefaultModel()
PlainDocument.public void setDocument(Document doc)
filterNewlines to
true and then calls the super behaviour to setup a view and
revalidate the text field.setDocument in class JTextComponentdoc - the document to setpublic String getUIClassID()
getUIClassID in class JTextComponentJComponent.setUI(javax.swing.plaf.ComponentUI),
JComponent.updateUI()public void addActionListener(ActionListener listener)
listener - the listener to addpublic void removeActionListener(ActionListener listener)
listener - the listener to removepublic ActionListener[] getActionListeners()
ActionListener objects.protected void fireActionPerformed()
ActionListener objects.public int getColumns()
public void setColumns(int columns)
columns - the number of columnsIllegalArgumentException - if columns < 0public int getHorizontalAlignment()
public void setHorizontalAlignment(int newAlign)
newAlign - must be one of: JTextField.LEFT, JTextField.CENTER,
JTextField.RIGHT, JTextField.LEADING, JTextField.TRAILING.IllegalArgumentException - if newAlign is not one of the above.public void setFont(Font newFont)
setFont in class JComponentnewFont - The new value of the propertyComponent.getFont()public Dimension getPreferredSize()
getPreferredSize in class JComponentComponent.setPreferredSize(java.awt.Dimension),
Component.getPreferredSize(),
Component.isPreferredSizeSet(),
ComponentUI.getPreferredSize(JComponent)public int getScrollOffset()
public void setScrollOffset(int offset)
offset - the scroll offsetpublic Action[] getActions()
getActions in class JTextComponentEditorKitTextUI.getEditorKit(javax.swing.text.JTextComponent),
EditorKit.getActions()public void postActionEvent()
public void setActionCommand(String command)
protected PropertyChangeListener createActionPropertyChangeListener(Action action)
protected void configurePropertiesFromAction(Action action)
protected int getColumnWidth()
public AccessibleContext getAccessibleContext()
JTextField.getAccessibleContext in interface AccessiblegetAccessibleContext in class JTextComponentJTextFieldpublic BoundedRangeModel getHorizontalVisibility()
public boolean isValidateRoot()
true, unless this is embedded in a
JViewport in which case the viewport takes responsibility of
validating.isValidateRoot in class JComponenttrue, unless this is embedded in a
JViewport in which case the viewport takes
responsibility of validatingpublic void scrollRectToVisible(Rectangle r)
JComponentscrollRectToVisible on the component's parent.
Components which can service this call should override.scrollRectToVisible in class JComponentr - The rectangle to make visible