|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.microedition.lcdui.Displayable | +--javax.microedition.lcdui.Screen | +--javax.microedition.lcdui.TextBox
The TextBox class is a Screen
that allows the user to enter
and edit text.
The TextBox has a maximum size, which is the number of characters that can be stored in the object at any time (its capacity). This limit is enforced when the user is editing text within the TextBox, as well as when the application program calls methods on the TextBox that modify its contents. The maximum size is the maximum stored capacity and is unrelated to the number of characters that may be displayed at any given time. The number of characters displayed and their arrangement into rows and columns are determined by the device.
The implementation may place a boundary on the maximum size, and the maximum
size actually assigned may be smaller than the application had requested.
The value actually assigned will be reflected in the value returned by getMaxSize()
. A defensively-written application should
compare this value to the maximum size requested and be prepared to handle
cases where they differ.
The text contained within a TextBox may be more than can be displayed at one time. If this is the case, the implementation will let the user scroll to view and edit any part of the text. This scrolling occurs transparently to the application.
TextBox has the concept of
input constraints that is identical to TextField. The
constraints
parameters of methods within the TextBox
class use constants defined in the TextField
class. See
the description of input constraints in the TextField class for the
definition of these constants.
Constructor Summary | |
TextBox(String title,
String text,
int maxSize,
int constraints)
Creates a new TextBox object with the given title string, initial contents, maximum size in characters, and constraints. |
Method Summary | |
void |
delete(int offset,
int length)
Deletes characters from the TextBox. |
int |
getCaretPosition()
Gets the current input position. |
int |
getChars(char[] data)
Copies the contents of the TextBox into a character array starting at index zero. |
int |
getConstraints()
Get the current input constraints of the TextBox. |
int |
getMaxSize()
Returns the maximum size (number of characters) that can be stored in this TextBox. |
String |
getString()
Gets the contents of the TextBox as a string value. |
void |
insert(char[] data,
int offset,
int length,
int position)
Inserts a subrange of an array of characters just prior to the given position. |
void |
insert(String src,
int position)
Inserts a string into the contents of the TextBox. |
void |
setChars(char[] data,
int offset,
int length)
Sets the contents of the TextBox from a character array, replacing the previous contents. |
void |
setConstraints(int constraints)
Sets the input constraints of the TextBox. |
void |
setInitialInputMode(String characterSubset)
Sets a hint to the implementation as to the input mode that should be used when the user initiates editing of this TextBox . |
int |
setMaxSize(int maxSize)
Sets the maximum size (number of characters) that can be contained in this TextBox. |
void |
setString(String text)
Sets the contents of the TextBox as a string value, replacing the previous contents. |
int |
size()
Gets the number of characters that are currently stored in this TextBox. |
Methods inherited from class javax.microedition.lcdui.Displayable |
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle, sizeChanged |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TextBox(String title, String text, int maxSize, int constraints)
title
- the title text to be shown at the top of the displaytext
- the initial contents of the text editing area, null
may be used to indicate no initial content.maxSize
- the maximum capacity in characters. The implementation
may limit boundary maximum capacity and the actual assigned capacity
may be smaller than requested. A defensive application will test the
actually given capacity with getMaxSize()
.constraints
- see description of input constraints in
TextField
IllegalArgumentException
- if maxSize is zero or less
IllegalArgumentException
- if the constraints parameter is
invalid
IllegalArgumentException
- if text is illegal for the specified
constraints
IllegalArgumentException
- if the length of the string
exceeds the requested maximum capacity, or the maximum capacity actually
assignedMethod Detail |
public void delete(int offset, int length)
offset
- the beginning of the region to be deletedlength
- the number of characters to be deleted
StringIndexOutOfBoundsException
- if offset and
length do not specify a valid range within the contents of the
TextBoxpublic int getCaretPosition()
public int getChars(char[] data)
data
- the character array to receive the value
ArrayIndexOutOfBoundsException
- if data is too short
for the contents
NullPointerException
- if data
is null
public int getConstraints()
TextField
public int getMaxSize()
public String getString()
public void insert(char[] data, int offset, int length, int position)
insert(String)
.
data
- the source of the character dataoffset
- the beginning of the region of characters to copylength
- the number of characters to copyposition
- the position at which insertion is to occur
ArrayIndexOutOfBoundsException
- if offset and
length do not specify a valid range within the data array
IllegalArgumentException
- if the resulting content is
illegal for the current input constraints
IllegalArgumentException
- if the insertion would exceed
the current maximum capacity
NullPointerException
- if src
is null
public void insert(String src, int position)
The current size of the contents is increased by the number of inserted characters. The resulting string must fit within the current maximum capacity.
If the application needs to simulate typing of characters it can
determine the location of the current insertion point ("caret") using the
getCaretPosition()
method. For example,
text.insert(s, text.getCaretPosition()) inserts the string s at
the current caret position.
src
- the String to be insertedposition
- the position at which insertion is to occur
IllegalArgumentException
- if the resulting contents are
illegal for the current input constraints
IllegalArgumentException
- if the insertion would exceed
the current maximum capacity
NullPointerException
- if src
is null
public void setChars(char[] data, int offset, int length)
data
array starting at array index
offset
and running for length
characters. If the data array is null, the TextBox is set to be
empty and the other parameters are ignored.
data
- the source of the character dataoffset
- the beginning of the region of characters to copylength
- the number of characters to copy
ArrayIndexOutOfBoundsException
- if offset and
length do not specify a valid range within the data array
IllegalArgumentException
- if the text is illegal for the
current input constraints
IllegalArgumentException
- if the text would exceed the
current maximum capacitypublic void setConstraints(int constraints)
constraints
- see input constraints in TextField
IllegalArgumentException
- if the value of the constraints
parameter is invalidpublic int setMaxSize(int maxSize)
maxSize
- the new maximum size
IllegalArgumentException
- if maxSize is zero or lesspublic void setString(String text)
text
- the new value of the TextBox
IllegalArgumentException
- if the text is illegal for the
current input constraints
IllegalArgumentException
- if the text would exceed the
current maximum capacitypublic int size()
public void setInitialInputMode(String characterSubset)
TextBox
. The
characterSubset
parameter names a subset of Unicode
characters that is used by the implementation to choose an initial
input mode. If null
is passed, the implementation should
choose a default input mode.
See Input Modes for a full explanation of input modes.
characterSubset
- a string naming a Unicode character subset,
or null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |