A
TextField
is the interface to Java's AWT TextField Component.
Yoix programs normally interact with a
TextField
using event handlers and by reading or writing the following fields:
| autotrim |
An
int
that is
1
when white space is automatically trimmed from both ends of every string
read from or written to the
text
field, and
0
otherwise.
| | background |
The
Color
that is used to paint the background of the textfield.
Reading returns a snapshot of the current color.
Writing immediately changes the background to the new color.
Storing
NULL
in
background
is special and means the textfield uses its preferred color, which is white.
| | caret |
An
int
that represents the position of the text insertion caret.
Reading returns the current position.
Writing immediately moves the caret to the new position.
| | columns |
An
int
that specifies the number of columns in a textfield.
Layout managers usually get the final say, so setting
columns
should be viewed as a request that will not always be honored.
Reading returns the number of columns currently used by the textfield.
Writing tries to immediately change the number of columns.
| | cursor |
An
Object
that should be an
int,
Image,
or
String
that selects the cursor shown when the pointer is over the textfield.
A
cursor
that is an
int
should be one of the cursors defined in the
yoix.awt.Cursor
dictionary.
A
cursor
that is an
Image
can describe the cursor using its
size
and
hotspot
fields and often draws it using its
paint
function.
A
cursor
that is a
String
should be the name of a cursor that is already defined in
yoix.awt.Cursor
or the name a local a file or URL that contains a GIF or JPEG image
that will be used as the cursor.
Reading returns the current cursor.
Writing immediately changes the textfield's cursor to the new value.
Storing
STANDARD_CURSOR
(the default) or
NULL
in
cursor
is special and means use the cursor assigned to the nearest component
that contains the textfield and was assigned a cursor other than
STANDARD_CURSOR;
if no component qualifies the textfield uses
TEXT_CURSOR.
| | echo |
An
int
that represents the character that is displayed in the textfield when
the user types characters.
A value of
0
means all typed characters appear.
Reading returns the current echo character.
Writing immediately changes the echo character to the new value.
| | edit |
An
int
that is
1
when the contents of the textfield can be changed, and
0
otherwise.
Reading returns the current edit flag.
Writing immediately sets the textfield's edit flag to the new state.
| | enabled |
An
int
that is
1
when the textfield can respond to user input, and
0
otherwise.
Reading returns the current state.
Writing immediately sets the textfield's state to the new value.
| | focusable |
An
int
that is non-zero (the default)
when the textfield can accept the keyboard focus and zero
when it can not.
Reading returns the textfield's current focusable state.
Writing immediately changes the textfield's focusable state to the new value,
which means the focus is automatically transferred if the new value is zero
and the textfield is the current focus owner.
| | focusowner |
A read-only
int
that is non-zero when the textfield has the focus.
| | font |
The
Font,
or font name if it is a
String,
used to paint the characters stored in the
text
field.
Reading returns a snapshot of the current font.
Writing immediately repaints the text in the new font.
| | foreground |
The
Color
that is used to paint the characters stored in the
text
field.
Reading returns a snapshot of the current color.
Writing immediately repaints the text in the new color.
Storing
NULL
in
foreground
is special and means the textfield uses its preferred color, which is black.
| | location |
A
Point
that determines the location of the textfield
in a coordinate system that has its origin at the upper left corner
of the container closest to the textfield (in the component hierarchy)
that actually contains it, positive x to the right, positive y down,
and a resolution of 72 dots per inch.
Reading returns a snapshot of the current location.
Writing is allowed, but layout managers usually get the final say, so setting
location
should be viewed as a request that may not be honored.
| | popup |
A
PopupMenu
that is associated with the textfield.
Reading returns the current popup menu.
Writing immediately shows the popup menu at the point in the textfield's coordinate
system specified by the popup menu's
location
field, assuming of course that the textfield is showing on the screen.
Storing
TRUE
in the popup menu's
visible
field, which was added in release 1.2.0, is an easy way to show the
popup menu that currently belongs to the textfield.
| | preferredsize |
A
Dimension
that is used by layout managers when they need to know the textfield's
preferred size in units of 72 dots per inch.
A
NULL
value means the textfield has no preference.
A non-positive height or width is allowed and simply means the textfield
has no preference for that dimension.
Reading returns the current preferred size.
Writing changes the preferred size and immediately notifies
root.layoutmanager,
which means the components contained in
root
may be repositioned and resized.
| | requestfocus |
An
int
that can be used to request or transfer the keyboard focus.
Storing a non-zero value in
requestfocus
tries to get the focus.
Storing
0
tries to transfer the focus.
Reading
requestfocus
does not currently return any useful information.
| | root |
An
Object
that is automatically updated by the interpreter's layout machinery
so it is always the top-level object that contains the textfield.
For example, put a textfield in a panel and
root
will be set to that panel;
add the panel to a frame and the textfield's
root
field will be set to that frame.
A textfield's event handlers can use
root
when they need to interact with the other components in the container.
| | selected |
Reading returns a
String
with the currently selected text.
Writing a
String
replaces the currently selected text with the supplied text.
The insertion caret is left at the end of the added text.
| | selectedends |
An
Array
that contains entries that are used to set the starting
and ending positions of the current selection.
Writing
NULL
to
selectedends
clears the current selection,
otherwise the first array element controls the start position,
while the second element controls the end position.
The starting position is either 0 or the integer value of the number at
selectedends[0].
The ending position is either the length of the
text
string, which puts it just to the right of the last character,
or the integer value of the number at
selectedends[1].
Requesting an ending value that is less than or equal to the starting
value also clears the current selection.
Reading returns an
Array
of two integers that are the starting and ending positions of the
current selection.
When writing, the insertion caret is set to the end of the selection.
| | showing |
A read-only
int
that is non-zero when the textfield is showing on the screen.
| | size |
A
Dimension
that determines the size of the textfield
in units of 72 dots per inch.
Reading returns a snapshot of the current size.
Writing is allowed, but layout managers usually get the final say, so setting
size
should be viewed as a request that may not be honored.
| | tag |
A
String
used to identify the textfield that is either supplied when
the textfield is declared, or automatically generated otherwise.
Add a textfield to a container, like a
Frame
or
Panel,
and the interpreter's layout machinery updates the
root
field so it points at the top-level container and then adds the textfield, as
tag,
to the
root.components
dictionary.
| | text |
A
String
of characters that is displayed in the textfield.
Reading returns the current text.
Writing immediately paints the new text.
| | visible |
An
int
that is
1
when the textfield is visible, and
0
otherwise.
Reading returns the current visibility.
Writing immediately sets the textfield's visibility to the new state.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
Event handlers are functions that must be added to a textfield when it is
declared.
The handlers that work with textfields are listed below;
the names should be familiar if you have done some Java programming.
The
itemStateChanged
event handler is only for menus.
| |
| Event Handlers: |
actionPerformed,
componentHidden,
componentMoved,
componentResized,
componentShown,
dragDropEnd,
dragEnter,
dragExit,
dragGestureRecognized,
dragMouseMoved,
dragOver,
drop,
dropActionChanged,
focusGained,
focusLost,
invocationRun,
itemStateChanged,
keyPressed,
keyReleased,
keyTyped,
mouseClicked,
mouseDragged,
mouseEntered,
mouseExited,
mouseMoved,
mousePressed,
mouseReleased,
mouseWheelMoved,
textValueChanged
| | |
| Example: |
The program,
import yoix.*.*;
Dialog d = {
Dimension size = NULL;
int modal = TRUE;
Array layout = {
new Panel {
GridLayout layoutmanager = {
int rows = 0;
int columns = 2;
};
Array layout = {
new Label {
String text = "Name";
int alignment = RIGHT;
},
new TextField {
String tag = "name";
int columns = 12;
focusGained(e) {
root.components.failed.text = "";
}
},
new Label {
String text = "Password";
int alignment = RIGHT;
},
new TextField {
String tag = "password";
int columns = 12;
int echo = '*';
focusGained(e) {
root.components.failed.text = "";
}
},
};
}, NORTH,
new Label {
String tag = "failed";
String text = "Login failed";
Color foreground = Color.red;
int alignment = CENTER;
}, CENTER
};
};
d.visible = TRUE;
is a non-trivial example that shows how labels and textfields can be
used to build a simple login dialog.
We will leave the obvious missing pieces, like adding buttons,
as an exercise.
| | |
| See Also: |
Button,
Canvas,
Checkbox,
Choice,
Dialog,
FileDialog,
Frame,
Label,
List,
Panel,
ScrollPane,
Scrollbar,
TableColumn,
TableManager,
TextArea,
TextCanvas,
TextTerm,
Window,
appendText,
deleteText,
insertText,
postEvent,
replaceText
|
|