| Constructor: |
public TextField() throws HeadlessException {
/* ensure that the necessary native libraries are loaded */
Toolkit.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
this("", 0);
}
Constructs a new text field. Throws:
HeadlessException - if GraphicsEnvironment.isHeadless()
returns true.
Also see:
- java.awt.GraphicsEnvironment#isHeadless
- exception:
HeadlessException - if GraphicsEnvironment.isHeadless()
returns true.
|
public TextField(String text) throws HeadlessException {
this(text, (text != null) ? text.length() : 0);
}
Constructs a new text field initialized with the specified text. Parameters:
text - the text to be displayed. If
text is null, the empty
string "" will be displayed.
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless()
returns true.
Also see:
- java.awt.GraphicsEnvironment#isHeadless
- exception:
HeadlessException - if GraphicsEnvironment.isHeadless()
returns true.
|
public TextField(int columns) throws HeadlessException {
this("", columns);
}
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. If
columns is less than 0,
columns is set to 0.
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless()
returns true.
Also see:
- java.awt.GraphicsEnvironment#isHeadless
- exception:
HeadlessException - if GraphicsEnvironment.isHeadless()
returns true.
|
public TextField(String text,
int columns) throws HeadlessException {
super(text);
this.columns = (columns >= 0) ? columns : 0;
}
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. If
text is null, the empty
string "" will be displayed.
columns - the number of columns. If
columns is less than 0,
columns is set to 0.
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless()
returns true.
Also see:
- java.awt.GraphicsEnvironment#isHeadless
- exception:
HeadlessException - if GraphicsEnvironment.isHeadless()
returns true.
|
| Methods from java.awt.Component: |
|---|
|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, doLayout, enable, enable, enableEvents, enableInputMethods, eventTypeEnabled, findNextFocusComponent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, generateName, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getGraphicsConfigurationImpl, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setPeer, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, translateEvent, update, validate |
| Method from java.awt.TextField Detail: |
public synchronized void addActionListener(ActionListener l) {
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.add(actionListener, l);
newEventsOnly = true;
}
|
public void addNotify() {
synchronized (getTreeLock()) {
if (peer == null)
peer = getToolkit().createTextField(this);
super.addNotify();
}
}
Creates the TextField's peer. The peer allows us to modify the
appearance of the TextField without changing its functionality. |
String constructComponentName() {
synchronized (TextField.class) {
return base + nameCounter++;
}
}
Construct a name for this component. Called by getName() when the
name is null. |
public boolean echoCharIsSet() {
return echoChar != 0;
}
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. |
boolean eventEnabled(AWTEvent e) {
if (e.id == ActionEvent.ACTION_PERFORMED) {
if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
actionListener != null) {
return true;
}
return false;
}
return super.eventEnabled(e);
}
|
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTTextField();
}
return accessibleContext;
}
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. |
public synchronized ActionListener[] getActionListeners() {
return (ActionListener[])(getListeners(ActionListener.class));
}
Returns an array of all the action listeners
registered on this textfield. |
public int getColumns() {
return columns;
}
Gets the number of columns in this text field. A column is an
approximate average character width that is platform-dependent. |
public char getEchoChar() {
return echoChar;
}
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. |
public T[] getListeners(Class listenerType) {
EventListener l = null;
if (listenerType == ActionListener.class) {
l = actionListener;
} else {
return super.getListeners(listenerType);
}
return AWTEventMulticaster.getListeners(l, listenerType);
}
Returns an array of all the objects currently registered
as FooListeners
upon this TextField.
FooListeners are registered using the
addFooListener method.
You can specify the listenerType argument
with a class literal, such as
FooListener.class.
For example, you can query a
TextField t
for 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. |
public Dimension getMinimumSize() {
return minimumSize();
}
Gets the minumum dimensions for this text field. |
public Dimension getMinimumSize(int columns) {
return minimumSize(columns);
}
Gets the minumum dimensions for a text field with
the specified number of columns. |
public Dimension getPreferredSize() {
return preferredSize();
}
Gets the preferred size of this text field. |
public Dimension getPreferredSize(int columns) {
return preferredSize(columns);
}
Gets the preferred size of this text field
with the specified number of columns. |
public Dimension minimumSize() {
synchronized (getTreeLock()) {
return (columns > 0) ?
minimumSize(columns) :
super.minimumSize();
}
} Deprecated! As - of JDK version 1.1,
replaced by getMinimumSize().
|
public Dimension minimumSize(int columns) {
synchronized (getTreeLock()) {
TextFieldPeer peer = (TextFieldPeer)this.peer;
return (peer != null) ?
peer.minimumSize(columns) :
super.minimumSize();
}
} Deprecated! As - of JDK version 1.1,
replaced by getMinimumSize(int).
|
protected String paramString() {
String str = super.paramString();
if (echoChar != 0) {
str += ",echo=" + echoChar;
}
return str;
}
Returns a string representing the state of this TextField.
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 be
null. |
public Dimension preferredSize() {
synchronized (getTreeLock()) {
return (columns > 0) ?
preferredSize(columns) :
super.preferredSize();
}
} Deprecated! As - of JDK version 1.1,
replaced by getPreferredSize().
|
public Dimension preferredSize(int columns) {
synchronized (getTreeLock()) {
TextFieldPeer peer = (TextFieldPeer)this.peer;
return (peer != null) ?
peer.preferredSize(columns) :
super.preferredSize();
}
} Deprecated! As - of JDK version 1.1,
replaced by getPreferredSize(int).
|
protected void processActionEvent(ActionEvent e) {
ActionListener listener = actionListener;
if (listener != null) {
listener.actionPerformed(e);
}
}
Processes action events occurring on this text field by
dispatching them to any registered
ActionListener objects.
This method is not called unless action events are
enabled for this component. Action events are enabled
when one of the following occurs:
- An
ActionListener object is registered
via addActionListener.
- Action events are enabled via
enableEvents.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception. |
protected void processEvent(AWTEvent e) {
if (e instanceof ActionEvent) {
processActionEvent((ActionEvent)e);
return;
}
super.processEvent(e);
}
Processes events on this text field. If the event
is an instance of ActionEvent,
it invokes the processActionEvent
method. Otherwise, it invokes processEvent
on the superclass.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception. |
public synchronized void removeActionListener(ActionListener l) {
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.remove(actionListener, l);
}
|
public void setColumns(int columns) {
int oldVal;
synchronized (this) {
oldVal = this.columns;
if (columns < 0) {
throw new IllegalArgumentException("columns less than zero.");
}
if (columns != oldVal) {
this.columns = columns;
}
}
if (columns != oldVal) {
invalidate();
}
}
Sets the number of columns in this text field. A column is an
approximate average character width that is platform-dependent. |
public void setEchoChar(char c) {
setEchoCharacter(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 = 0 allows
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. |
public synchronized void setEchoCharacter(char c) {
if (echoChar != c) {
echoChar = c;
TextFieldPeer peer = (TextFieldPeer)this.peer;
if (peer != null) {
peer.setEchoCharacter(c);
}
}
} Deprecated! As - of JDK version 1.1,
replaced by setEchoChar(char).
|
public void setText(String t) {
super.setText(t);
// This could change the preferred size of the Component.
if (valid) {
invalidate();
}
}
Sets the text that is presented by this
text component to be the specified text. |