Class TextField
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
TextField object is a text component
that allows for the editing of a single line of text.
For example, the following image depicts a frame with four
text fields of varying widths. Two of these text fields
display the predefined text "Hello".
Here is the code that produces these four text fields:
TextField tf1, tf2, tf3, tf4;
// a blank text field
tf1 = new TextField();
// blank field of 20 columns
tf2 = new TextField("", 20);
// predefined text displayed
tf3 = new TextField("Hello!");
// predefined text in 30 columns
tf4 = new TextField("Hello", 30);
Every time the user types a key in the text field, one or
more key events are sent to the text field. A KeyEvent
may be one of three types: keyPressed, keyReleased, or keyTyped.
The properties of a key event indicate which of these types
it is, as well as additional information about the event,
such as what modifiers are applied to the key event and the
time at which the event occurred.
The key event is passed to every KeyListener
or KeyAdapter object which registered to receive such
events using the component's addKeyListener method.
(KeyAdapter objects implement the
KeyListener interface.)
It is also possible to fire an ActionEvent.
If action events are enabled for the text field, they may
be fired by pressing the Return key.
The TextField class's processEvent
method examines the action event and passes it along to
processActionEvent. The latter method redirects the
event to any ActionListener objects that have
registered to receive action events generated by this
text field.
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThis class implements accessibility support for theTextFieldclass.Nested classes/interfaces declared in class TextComponent
TextComponent.AccessibleAWTTextComponentModifier and TypeClassDescriptionprotected classThis class implements accessibility support for theTextComponentclass.Nested classes/interfaces declared in class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyModifier and TypeClassDescriptionprotected classInner class of Component used to provide default support for accessibility.static enumEnumeration of the common ways the baseline of a component can change as the size changes.protected classInner class for blitting offscreen surfaces to a component.protected classInner class for flipping buffers on a component. -
Field Summary
Fields declared in class TextComponent
textListenerModifier and TypeFieldDescriptionprotected TextListenerA list of listeners that will receive events from this object.Fields declared in class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTModifier and TypeFieldDescriptionprotected AccessibleContextTheAccessibleContextassociated with thisComponent.static final floatEase-of-use constant forgetAlignmentY.static final floatEase-of-use constant forgetAlignmentYandgetAlignmentX.static final floatEase-of-use constant forgetAlignmentX.static final floatEase-of-use constant forgetAlignmentX.static final floatEase-of-use constant forgetAlignmentY().Fields declared in interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHModifier and TypeFieldDescriptionstatic final intThis flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously was aborted before production was complete.static final intThis flag in the infoflags argument to imageUpdate indicates that a static image which was previously drawn is now complete and can be drawn again in its final form.static final intThis flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously has encountered an error.static final intThis flag in the infoflags argument to imageUpdate indicates that another complete frame of a multi-frame image which was previously drawn is now available to be drawn again.static final intThis flag in the infoflags argument to imageUpdate indicates that the height of the base image is now available and can be taken from the height argument to the imageUpdate callback method.static final intThis flag in the infoflags argument to imageUpdate indicates that the properties of the image are now available.static final intThis flag in the infoflags argument to imageUpdate indicates that more pixels needed for drawing a scaled variation of the image are available.static final intThis flag in the infoflags argument to imageUpdate indicates that the width of the base image is now available and can be taken from the width argument to the imageUpdate callback method. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new text field.TextField(int columns) Constructs a new empty text field with the specified number of columns.Constructs a new text field initialized with the specified text.Constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the specified number of columns. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified action listener to receive action events from this text field.voidCreates the TextField's peer.booleanIndicates whether or not this text field has a character set for echoing.Gets the AccessibleContext associated with this TextField.Returns an array of all the action listeners registered on this textfield.intGets the number of columns in this text field.charGets the character that is to be used for echoing.<T extends EventListener>
T[]getListeners(Class<T> listenerType) Returns an array of all the objects currently registered asFooListeners upon thisTextField.Gets the minimum dimensions for this text field.getMinimumSize(int columns) Gets the minimum dimensions for a text field with the specified number of columns.Gets the preferred size of this text field.getPreferredSize(int columns) Gets the preferred size of this text field with the specified number of columns.Deprecated.minimumSize(int columns) Deprecated.As of JDK version 1.1, replaced bygetMinimumSize(int).protected StringReturns a string representing the state of thisTextField.Deprecated.As of JDK version 1.1, replaced bygetPreferredSize().preferredSize(int columns) Deprecated.As of JDK version 1.1, replaced bygetPreferredSize(int).protected voidProcesses action events occurring on this text field by dispatching them to any registeredActionListenerobjects.protected voidProcesses events on this text field.voidRemoves the specified action listener so that it no longer receives action events from this text field.voidsetColumns(int columns) Sets the number of columns in this text field.voidsetEchoChar(char c) Sets the echo character for this text field.voidsetEchoCharacter(char c) Deprecated.As of JDK version 1.1, replaced bysetEchoChar(char).voidSets the text that is presented by this text component to be the specified text.Methods declared in class TextComponent
addTextListener, enableInputMethods, getBackground, getCaretPosition, getSelectedText, getSelectionEnd, getSelectionStart, getText, getTextListeners, isEditable, processTextEvent, removeNotify, removeTextListener, select, selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStartModifier and TypeMethodDescriptionvoidAdds the specified text event listener to receive text events from this text component.voidenableInputMethods(boolean enable) Enables or disables input method support for this text component.Gets the background color of this text component.intReturns the position of the text insertion caret.Returns the selected text from the text that is presented by this text component.intGets the end position of the selected text in this text component.intGets the start position of the selected text in this text component.getText()Returns the text that is presented by this text component.Returns an array of all the text listeners registered on this text component.booleanIndicates whether or not this text component is editable.protected voidProcesses text events occurring on this text component by dispatching them to any registeredTextListenerobjects.voidRemoves theTextComponent's peer.voidRemoves the specified text event listener so that it no longer receives text events from this text component Iflisnull, no exception is thrown and no action is performed.voidselect(int selectionStart, int selectionEnd) Selects the text between the specified start and end positions.voidSelects all the text in this text component.voidSets the background color of this text component.voidsetCaretPosition(int position) Sets the position of the text insertion caret.voidsetEditable(boolean b) Sets the flag that determines whether or not this text component is editable.voidsetSelectionEnd(int selectionEnd) Sets the selection end for this text component to the specified position.voidsetSelectionStart(int selectionStart) Sets the selection start for this text component to the specified position.Methods declared in class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validateModifier and TypeMethodDescriptionbooleanDeprecated.As of JDK version 1.1, should register this component as ActionListener on component which fires action events.voidAdds the specified popup menu to the component.voidAdds the specified component listener to receive component events from this component.voidAdds the specified focus listener to receive focus events from this component when this component gains input focus.voidAdds the specified hierarchy bounds listener to receive hierarchy bounds events from this component when the hierarchy to which this container belongs changes.voidAdds the specified hierarchy listener to receive hierarchy changed events from this component when the hierarchy to which this container belongs changes.voidAdds the specified input method listener to receive input method events from this component.voidAdds the specified key listener to receive key events from this component.voidAdds the specified mouse listener to receive mouse events from this component.voidAdds the specified mouse motion listener to receive mouse motion events from this component.voidAdds the specified mouse wheel listener to receive mouse wheel events from this component.voidAdds a PropertyChangeListener to the listener list.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) Adds a PropertyChangeListener to the listener list for a specific property.voidapplyComponentOrientation(ComponentOrientation orientation) Sets theComponentOrientationproperty of this component and all components contained within it.booleanareFocusTraversalKeysSet(int id) Returns whether the Set of focus traversal keys for the given focus traversal operation has been explicitly defined for this Component.bounds()Deprecated.As of JDK version 1.1, replaced bygetBounds().intcheckImage(Image image, int width, int height, ImageObserver observer) Returns the status of the construction of a screen representation of the specified image.intcheckImage(Image image, ImageObserver observer) Returns the status of the construction of a screen representation of the specified image.protected AWTEventcoalesceEvents(AWTEvent existingEvent, AWTEvent newEvent) Potentially coalesce an event being posted with an existing event.booleancontains(int x, int y) Checks whether this component "contains" the specified point, wherexandyare defined to be relative to the coordinate system of this component.booleanChecks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the coordinate system of this component.createImage(int width, int height) Creates an off-screen drawable image to be used for double buffering.createImage(ImageProducer producer) Creates an image from the specified image producer.createVolatileImage(int width, int height) Creates a volatile off-screen drawable image to be used for double buffering.createVolatileImage(int width, int height, ImageCapabilities caps) Creates a volatile off-screen drawable image, with the given capabilities.voidDeprecated.As of JDK version 1.1, replaced bydispatchEvent(AWTEvent e).voiddisable()Deprecated.As of JDK version 1.1, replaced bysetEnabled(boolean).protected final voiddisableEvents(long eventsToDisable) Disables the events defined by the specified event mask parameter from being delivered to this component.final voidDispatches an event to this component or one of its sub components.voiddoLayout()Prompts the layout manager to lay out this component.voidenable()Deprecated.As of JDK version 1.1, replaced bysetEnabled(boolean).voidenable(boolean b) Deprecated.As of JDK version 1.1, replaced bysetEnabled(boolean).protected final voidenableEvents(long eventsToEnable) Enables the events defined by the specified event mask parameter to be delivered to this component.protected voidfirePropertyChange(String propertyName, boolean oldValue, boolean newValue) Support for reporting bound property changes for boolean properties.voidfirePropertyChange(String propertyName, byte oldValue, byte newValue) Reports a bound property change.voidfirePropertyChange(String propertyName, char oldValue, char newValue) Reports a bound property change.voidfirePropertyChange(String propertyName, double oldValue, double newValue) Reports a bound property change.voidfirePropertyChange(String propertyName, float oldValue, float newValue) Reports a bound property change.protected voidfirePropertyChange(String propertyName, int oldValue, int newValue) Support for reporting bound property changes for integer properties.voidfirePropertyChange(String propertyName, long oldValue, long newValue) Reports a bound property change.voidfirePropertyChange(String propertyName, short oldValue, short newValue) Reports a bound property change.protected voidfirePropertyChange(String propertyName, Object oldValue, Object newValue) Support for reporting bound property changes for Object properties.floatReturns the alignment along the x axis.floatReturns the alignment along the y axis.intgetBaseline(int width, int height) Returns the baseline.Returns an enum indicating how the baseline of the component changes as the size changes.Gets the bounds of this component in the form of aRectangleobject.Stores the bounds of this component into "return value" rv and return rv.Gets the instance ofColorModelused to display the component on the output device.getComponentAt(int x, int y) Determines if this component or one of its immediate subcomponents contains the (x, y) location, and if so, returns the containing component.Returns the component or subcomponent that contains the specified point.Returns an array of all the component listeners registered on this component.Retrieves the language-sensitive orientation that is to be used to order the elements or text within this component.Gets the cursor set in the component.Gets theDropTargetassociated with thisComponent.Returns the Container which is the focus cycle root of this Component's focus traversal cycle.Returns an array of all the focus listeners registered on this component.getFocusTraversalKeys(int id) Returns the Set of focus traversal keys for a given traversal operation for this Component.booleanReturns whether focus traversal keys are enabled for this Component.getFont()Gets the font of this component.getFontMetrics(Font font) Gets the font metrics for the specified font.Gets the foreground color of this component.Creates a graphics context for this component.Gets theGraphicsConfigurationassociated with thisComponent.intReturns the current height of this component.Returns an array of all the hierarchy bounds listeners registered on this component.Returns an array of all the hierarchy listeners registered on this component.booleanReturns whether or not paint messages received from the operating system should be ignored.Gets the input context used by this component for handling the communication with input methods when text is entered in this component.Returns an array of all the input method listeners registered on this component.Gets the input method request handler which supports requests from input methods for this component.Returns an array of all the key listeners registered on this component.Gets the locale of this component.Gets the location of this component in the form of a point specifying the component's top-left corner.getLocation(Point rv) Stores the x,y origin of this component into "return value" rv and return rv.Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.Gets the maximum size of this component.Returns an array of all the mouse listeners registered on this component.Returns an array of all the mouse motion listeners registered on this component.Returns the position of the mouse pointer in thisComponent's coordinate space if theComponentis directly under the mouse pointer, otherwise returnsnull.Returns an array of all the mouse wheel listeners registered on this component.getName()Gets the name of the component.Gets the parent of this component.Returns an array of all the property change listeners registered on this component.getPropertyChangeListeners(String propertyName) Returns an array of all the listeners which have been associated with the named property.getSize()Returns the size of this component in the form of aDimensionobject.Stores the width/height of this component into "return value" rv and return rv.Gets the toolkit of this component.final ObjectGets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations.intgetWidth()Returns the current width of this component.intgetX()Returns the current x coordinate of the components origin.intgetY()Returns the current y coordinate of the components origin.booleanDeprecated.As of JDK version 1.1, replaced by processFocusEvent(FocusEvent).booleanhandleEvent(Event evt) Deprecated.As of JDK version 1.1 replaced by processEvent(AWTEvent).booleanhasFocus()Returnstrueif thisComponentis the focus owner.voidhide()Deprecated.As of JDK version 1.1, replaced bysetVisible(boolean).booleanimageUpdate(Image img, int infoflags, int x, int y, int w, int h) Repaints the component when the image has changed.booleaninside(int x, int y) Deprecated.As of JDK version 1.1, replaced by contains(int, int).voidInvalidates this component and its ancestors.booleanReturns whether the background color has been explicitly set for this Component.booleanReturns whether the cursor has been explicitly set for this Component.booleanDetermines whether this component is displayable.booleanReturns true if this component is painted to an offscreen image ("buffer") that's copied to the screen later.booleanDetermines whether this component is enabled.booleanReturns whether this Component can be focused.booleanisFocusCycleRoot(Container container) Returns whether the specified Container is the focus cycle root of this Component's focus traversal cycle.booleanReturnstrueif thisComponentis the focus owner.booleanDeprecated.As of 1.4, replaced byisFocusable().booleanReturns whether the font has been explicitly set for this Component.booleanReturns whether the foreground color has been explicitly set for this Component.booleanA lightweight component doesn't have a native toolkit peer.booleanReturns true if the maximum size has been set to a non-nullvalue otherwise returns false.booleanReturns whether or notsetMinimumSizehas been invoked with a non-null value.booleanisOpaque()Returns true if this component is completely opaque, returns false by default.booleanReturns true if the preferred size has been set to a non-nullvalue otherwise returns false.booleanDetermines whether this component is showing on screen.booleanisValid()Determines whether this component is valid.booleanDetermines whether this component should be visible when its parent is visible.booleanDeprecated.As of JDK version 1.1, replaced by processKeyEvent(KeyEvent).booleanDeprecated.As of JDK version 1.1, replaced by processKeyEvent(KeyEvent).voidlayout()Deprecated.As of JDK version 1.1, replaced bydoLayout().voidlist()Prints a listing of this component to the standard system output streamSystem.out.voidlist(PrintStream out) Prints a listing of this component to the specified output stream.voidlist(PrintStream out, int indent) Prints out a list, starting at the specified indentation, to the specified print stream.voidlist(PrintWriter out) Prints a listing to the specified print writer.voidlist(PrintWriter out, int indent) Prints out a list, starting at the specified indentation, to the specified print writer.locate(int x, int y) Deprecated.As of JDK version 1.1, replaced by getComponentAt(int, int).location()Deprecated.As of JDK version 1.1, replaced bygetLocation().booleanDeprecated.As of JDK version 1.1, replaced by processFocusEvent(FocusEvent).booleanDeprecated.As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).booleanDeprecated.As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent).booleanmouseEnter(Event evt, int x, int y) Deprecated.As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).booleanDeprecated.As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).booleanDeprecated.As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent).booleanDeprecated.As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).voidmove(int x, int y) Deprecated.As of JDK version 1.1, replaced bysetLocation(int, int).voidDeprecated.As of JDK version 1.1, replaced by transferFocus().voidPaints this component.voidPaints this component and all of its subcomponents.booleanDeprecated.As of JDK version 1.1, replaced by dispatchEvent(AWTEvent).booleanprepareImage(Image image, int width, int height, ImageObserver observer) Prepares an image for rendering on this component at the specified width and height.booleanprepareImage(Image image, ImageObserver observer) Prepares an image for rendering on this component.voidPrints this component.voidPrints this component and all of its subcomponents.protected voidProcesses component events occurring on this component by dispatching them to any registeredComponentListenerobjects.protected voidProcesses focus events occurring on this component by dispatching them to any registeredFocusListenerobjects.protected voidProcesses hierarchy bounds events occurring on this component by dispatching them to any registeredHierarchyBoundsListenerobjects.protected voidProcesses hierarchy events occurring on this component by dispatching them to any registeredHierarchyListenerobjects.protected voidProcesses input method events occurring on this component by dispatching them to any registeredInputMethodListenerobjects.protected voidProcesses key events occurring on this component by dispatching them to any registeredKeyListenerobjects.protected voidProcesses mouse events occurring on this component by dispatching them to any registeredMouseListenerobjects.protected voidProcesses mouse motion events occurring on this component by dispatching them to any registeredMouseMotionListenerobjects.protected voidProcesses mouse wheel events occurring on this component by dispatching them to any registeredMouseWheelListenerobjects.voidremove(MenuComponent popup) Removes the specified popup menu from the component.voidRemoves the specified component listener so that it no longer receives component events from this component.voidRemoves the specified focus listener so that it no longer receives focus events from this component.voidRemoves the specified hierarchy bounds listener so that it no longer receives hierarchy bounds events from this component.voidRemoves the specified hierarchy listener so that it no longer receives hierarchy changed events from this component.voidRemoves the specified input method listener so that it no longer receives input method events from this component.voidRemoves the specified key listener so that it no longer receives key events from this component.voidRemoves the specified mouse listener so that it no longer receives mouse events from this component.voidRemoves the specified mouse motion listener so that it no longer receives mouse motion events from this component.voidRemoves the specified mouse wheel listener so that it no longer receives mouse wheel events from this component.voidRemoves a PropertyChangeListener from the listener list.voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener) Removes aPropertyChangeListenerfrom the listener list for a specific property.voidrepaint()Repaints this component.voidrepaint(int x, int y, int width, int height) Repaints the specified rectangle of this component.voidrepaint(long tm) Repaints the component.voidrepaint(long tm, int x, int y, int width, int height) Repaints the specified rectangle of this component withintmmilliseconds.voidRequests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window.protected booleanrequestFocus(boolean temporary) Requests that thisComponentget the input focus, and that thisComponent's top-level ancestor become the focusedWindow.protected booleanrequestFocus(boolean temporary, FocusEvent.Cause cause) Requests by the reason ofcausethat thisComponentget the input focus, and that thisComponent's top-level ancestor become the focusedWindow.voidrequestFocus(FocusEvent.Cause cause) Requests by the reason ofcausethat this Component get the input focus, and that this Component's top-level ancestor become the focused Window.booleanRequests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window.protected booleanrequestFocusInWindow(boolean temporary) Requests that thisComponentget the input focus, if thisComponent's top-level ancestor is already the focusedWindow.booleanRequests by the reason ofcausethat this Component get the input focus, if this Component's top-level ancestor is already the focused Window.voidreshape(int x, int y, int width, int height) Deprecated.As of JDK version 1.1, replaced bysetBounds(int, int, int, int).voidresize(int width, int height) Deprecated.As of JDK version 1.1, replaced bysetSize(int, int).voidDeprecated.As of JDK version 1.1, replaced bysetSize(Dimension).voidRevalidates the component hierarchy up to the nearest validate root.voidsetBounds(int x, int y, int width, int height) Moves and resizes this component.voidMoves and resizes this component to conform to the new bounding rectangler.voidSets the language-sensitive orientation that is to be used to order the elements or text within this component.voidSets the cursor image to the specified cursor.voidAssociate aDropTargetwith this component.voidsetEnabled(boolean b) Enables or disables this component, depending on the value of the parameterb.voidsetFocusable(boolean focusable) Sets the focusable state of this Component to the specified value.voidsetFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes) Sets the focus traversal keys for a given traversal operation for this Component.voidsetFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled) Sets whether focus traversal keys are enabled for this Component.voidSets the font of this component.voidSets the foreground color of this component.voidsetIgnoreRepaint(boolean ignoreRepaint) Sets whether or not paint messages received from the operating system should be ignored.voidSets the locale of this component.voidsetLocation(int x, int y) Moves this component to a new location.voidsetLocation(Point p) Moves this component to a new location.voidsetMaximumSize(Dimension maximumSize) Sets the maximum size of this component to a constant value.voidsetMinimumSize(Dimension minimumSize) Sets the minimum size of this component to a constant value.voidsetMixingCutoutShape(Shape shape) Sets a 'mixing-cutout' shape for this lightweight component.voidSets the name of the component to the specified string.voidsetPreferredSize(Dimension preferredSize) Sets the preferred size of this component to a constant value.voidsetSize(int width, int height) Resizes this component so that it has widthwidthand heightheight.voidResizes this component so that it has widthd.widthand heightd.height.voidsetVisible(boolean b) Shows or hides this component depending on the value of parameterb.voidshow()Deprecated.As of JDK version 1.1, replaced bysetVisible(boolean).voidshow(boolean b) Deprecated.As of JDK version 1.1, replaced bysetVisible(boolean).size()Deprecated.As of JDK version 1.1, replaced bygetSize().toString()Returns a string representation of this component and its values.voidTransfers the focus to the next component, as though this Component were the focus owner.voidTransfers the focus to the previous component, as though this Component were the focus owner.voidTransfers the focus up one focus traversal cycle.voidUpdates this component.voidvalidate()Validates this component.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
TextField
Constructs a new text field.- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
-
TextField
Constructs a new text field initialized with the specified text.- Parameters:
text- the text to be displayed. Iftextisnull, the empty string""will be displayed. Iftextcontains EOL and/or LF characters, then each will be replaced by space character.- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
-
TextField
Constructs a new empty text field with the specified number of columns. A column is an approximate average character width that is platform-dependent.- Parameters:
columns- the number of columns. Ifcolumnsis less than0,columnsis set to0.- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
-
TextField
Constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the specified number of columns. A column is an approximate average character width that is platform-dependent.- Parameters:
text- the text to be displayed. Iftextisnull, the empty string""will be displayed. Iftextcontains EOL and/or LF characters, then each will be replaced by space character.columns- the number of columns. Ifcolumnsis less than0,columnsis set to0.- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
-
-
Method Details
-
addNotify
public void addNotify()Creates the TextField's peer. The peer allows us to modify the appearance of the TextField without changing its functionality.- Overrides:
addNotifyin classTextComponent- See Also:
-
getEchoChar
public char getEchoChar()Gets the character that is to be used for echoing.An echo character is useful for text fields where user input should not be echoed to the screen, as in the case of a text field for entering a password. If
echoChar=0, user input is echoed to the screen unchanged.A Java platform implementation may support only a limited, non-empty set of echo characters. This function returns the echo character originally requested via setEchoChar(). The echo character actually used by the TextField implementation might be different.
- Returns:
- the echo character for this text field.
- See Also:
-
setEchoChar
public void setEchoChar(char c) Sets the echo character for this text field.An echo character is useful for text fields where user input should not be echoed to the screen, as in the case of a text field for entering a password. Setting
echoChar=0allows user input to be echoed to the screen again.A Java platform implementation may support only a limited, non-empty set of echo characters. Attempts to set an unsupported echo character will cause the default echo character to be used instead. Subsequent calls to getEchoChar() will return the echo character originally requested. This might or might not be identical to the echo character actually used by the TextField implementation.
- Parameters:
c- the echo character for this text field.- Since:
- 1.1
- See Also:
-
setEchoCharacter
Deprecated.As of JDK version 1.1, replaced bysetEchoChar(char).Sets the character to be echoed when protected input is displayed.- Parameters:
c- the echo character for this text field
-
setText
Sets the text that is presented by this text component to be the specified text.- Overrides:
setTextin classTextComponent- Parameters:
t- the new text. Iftisnull, the empty string""will be displayed. Iftcontains EOL and/or LF characters, then each will be replaced by space character.- See Also:
-
echoCharIsSet
public boolean echoCharIsSet()Indicates whether or not this text field has a character set for echoing.An echo character is useful for text fields where user input should not be echoed to the screen, as in the case of a text field for entering a password.
- Returns:
trueif this text field has a character set for echoing;falseotherwise.- See Also:
-
getColumns
public int getColumns()Gets the number of columns in this text field. A column is an approximate average character width that is platform-dependent.- Returns:
- the number of columns.
- Since:
- 1.1
- See Also:
-
setColumns
public void setColumns(int columns) Sets the number of columns in this text field. A column is an approximate average character width that is platform-dependent.- Parameters:
columns- the number of columns.- Throws:
IllegalArgumentException- if the value supplied forcolumnsis less than0.- Since:
- 1.1
- See Also:
-
getPreferredSize
Gets the preferred size of this text field with the specified number of columns.- Parameters:
columns- the number of columns in this text field.- Returns:
- the preferred dimensions for displaying this text field.
- Since:
- 1.1
-
preferredSize
Deprecated.As of JDK version 1.1, replaced bygetPreferredSize(int).Returns the preferred size for this text field with the specified number of columns.- Parameters:
columns- the number of columns- Returns:
- the preferred size for the text field
-
getPreferredSize
Gets the preferred size of this text field.- Overrides:
getPreferredSizein classComponent- Returns:
- the preferred dimensions for displaying this text field.
- Since:
- 1.1
- See Also:
-
preferredSize
Deprecated.As of JDK version 1.1, replaced bygetPreferredSize().Description copied from class:ComponentReturns the component's preferred size.- Overrides:
preferredSizein classComponent- Returns:
- the component's preferred size
-
getMinimumSize
Gets the minimum dimensions for a text field with the specified number of columns.- Parameters:
columns- the number of columns in this text field.- Returns:
- the minimum size for this text field
- Since:
- 1.1
-
minimumSize
Deprecated.As of JDK version 1.1, replaced bygetMinimumSize(int).Returns the minimum dimensions for a text field with the specified number of columns.- Parameters:
columns- the number of columns- Returns:
- the minimum size for this text field
-
getMinimumSize
Gets the minimum dimensions for this text field.- Overrides:
getMinimumSizein classComponent- Returns:
- the minimum dimensions for displaying this text field.
- Since:
- 1.1
- See Also:
-
minimumSize
Deprecated.As of JDK version 1.1, replaced bygetMinimumSize().Description copied from class:ComponentReturns the minimum size of this component.- Overrides:
minimumSizein classComponent- Returns:
- the minimum size of this component
-
addActionListener
Adds the specified action listener to receive action events from this text field. If l is null, no exception is thrown and no action is performed.Refer to AWT Threading Issues for details on AWT's threading model.
- Parameters:
l- the action listener.- Since:
- 1.1
- See Also:
-
removeActionListener
Removes the specified action listener so that it no longer receives action events from this text field. If l is null, no exception is thrown and no action is performed.Refer to AWT Threading Issues for details on AWT's threading model.
- Parameters:
l- the action listener.- Since:
- 1.1
- See Also:
-
getActionListeners
Returns an array of all the action listeners registered on this textfield.- Returns:
- all of this textfield's
ActionListeners or an empty array if no action listeners are currently registered - Since:
- 1.4
- See Also:
-
getListeners
Returns an array of all the objects currently registered asFooListeners upon thisTextField.FooListeners are registered using theaddFooListenermethod.You can specify the
listenerTypeargument with a class literal, such asFooListener.class. For example, you can query aTextField tfor its action listeners with the following code:ActionListener[] als = (ActionListener[])(t.getListeners(ActionListener.class));
If no such listeners exist, this method returns an empty array.- Overrides:
getListenersin classTextComponent- Type Parameters:
T- the type of the listeners- Parameters:
listenerType- the type of listeners requested; this parameter should specify an interface that descends fromjava.util.EventListener- Returns:
- an array of all objects registered as
FooListeners on this textfield, or an empty array if no such listeners have been added - Throws:
ClassCastException- iflistenerTypedoesn't specify a class or interface that implementsjava.util.EventListener- Since:
- 1.3
- See Also:
-
processEvent
Processes events on this text field. If the event is an instance ofActionEvent, it invokes theprocessActionEventmethod. Otherwise, it invokesprocessEventon the superclass.Note that if the event parameter is
nullthe behavior is unspecified and may result in an exception.- Overrides:
processEventin classTextComponent- Parameters:
e- the event- Since:
- 1.1
- See Also:
-
processActionEvent
Processes action events occurring on this text field by dispatching them to any registeredActionListenerobjects.This method is not called unless action events are enabled for this component. Action events are enabled when one of the following occurs:
- An
ActionListenerobject is registered viaaddActionListener. - Action events are enabled via
enableEvents.
Note that if the event parameter is
nullthe behavior is unspecified and may result in an exception.- Parameters:
e- the action event- Since:
- 1.1
- See Also:
- An
-
paramString
Returns a string representing the state of thisTextField. 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 benull.- Overrides:
paramStringin classTextComponent- Returns:
- the parameter string of this text field
-
getAccessibleContext
Gets the AccessibleContext associated with this TextField. For text fields, the AccessibleContext takes the form of an AccessibleAWTTextField. A new AccessibleAWTTextField instance is created if necessary.- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classTextComponent- Returns:
- an AccessibleAWTTextField that serves as the AccessibleContext of this TextField
- Since:
- 1.3
-
getMinimumSize().