public class TextField extends Widget
The preferred height of a text field is the height of the TextField.TextFieldStyle.font and TextField.TextFieldStyle.background.
The preferred width of a text field is 150, a relatively arbitrary size.
The text field will copy the currently selected text when ctrl+c is pressed, and paste any text in the clipboard when ctrl+v is
pressed. Clipboard functionality is provided via the Clipboard interface. Currently there are two standard
implementations, one for the desktop and one for Android. The Android clipboard is a stub, as copy & pasting on Android is not
supported yet.
The text field allows you to specify an TextField.OnscreenKeyboard for displaying a softkeyboard and piping all key events
generated by the keyboard to the text field. There are two standard implementations, one for the desktop and one for Android.
The desktop keyboard is a stub, as a softkeyboard is not needed on the desktop. The Android TextField.OnscreenKeyboard
implementation will bring up the default IME.
| Modifier and Type | Class and Description |
|---|---|
static class |
TextField.DefaultOnscreenKeyboard
The default
TextField.OnscreenKeyboard used by all TextField instances. |
static interface |
TextField.OnscreenKeyboard
An interface for onscreen keyboards.
|
static interface |
TextField.TextFieldFilter
Interface for filtering characters entered into the text field.
|
static interface |
TextField.TextFieldListener
Interface for listening to typed characters.
|
static class |
TextField.TextFieldStyle
The style for a text field, see
TextField. |
| Constructor and Description |
|---|
TextField(java.lang.String text,
Skin skin) |
TextField(java.lang.String text,
Skin skin,
java.lang.String styleName) |
TextField(java.lang.String text,
TextField.TextFieldStyle style) |
| Modifier and Type | Method and Description |
|---|---|
void |
clearSelection() |
void |
copy()
Copies the contents of this TextField to the
Clipboard implementation set on this TextField. |
void |
cut()
Copies the selected contents of this TextField to the
Clipboard implementation set on this TextField, then removes
it. |
void |
draw(SpriteBatch batch,
float parentAlpha)
If this method is overridden, the super method or
Widget.validate() should be called to ensure the widget is laid out. |
int |
getCursorPosition() |
int |
getMaxLength() |
java.lang.String |
getMessageText() |
TextField.OnscreenKeyboard |
getOnscreenKeyboard()
Default is an instance of
TextField.DefaultOnscreenKeyboard. |
float |
getPrefHeight() |
float |
getPrefWidth() |
TextField.TextFieldStyle |
getStyle()
Returns the text field's style.
|
java.lang.String |
getText() |
TextField.TextFieldFilter |
getTextFieldFilter() |
boolean |
isDisabled() |
boolean |
isPasswordMode() |
void |
next(boolean up)
Focuses the next TextField.
|
void |
selectAll() |
void |
setBlinkTime(float blinkTime) |
void |
setClipboard(Clipboard clipboard) |
void |
setCursorPosition(int cursorPosition)
Sets the cursor position and clears any selection.
|
void |
setDisabled(boolean disabled) |
void |
setFocusTraversal(boolean focusTraversal)
If true (the default), tab/shift+tab will move to the next text field.
|
void |
setMaxLength(int maxLength) |
void |
setMessageText(java.lang.String messageText)
Sets the text that will be drawn in the text field if no text has been entered.
|
void |
setOnscreenKeyboard(TextField.OnscreenKeyboard keyboard) |
void |
setPasswordCharacter(char passwordCharacter) |
void |
setPasswordMode(boolean passwordMode)
If true, the text in this text field will be shown as bullet characters.
|
void |
setRightAligned(boolean rightAligned) |
void |
setSelection(int selectionStart,
int selectionEnd)
Sets the selected text.
|
void |
setStyle(TextField.TextFieldStyle style) |
void |
setText(java.lang.String text) |
void |
setTextFieldFilter(TextField.TextFieldFilter filter) |
void |
setTextFieldListener(TextField.TextFieldListener listener) |
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, layout, needsLayout, pack, setFillParent, setLayoutEnabled, validateact, addAction, addCaptureListener, addListener, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getWidth, getX, getY, getZIndex, hasParent, hit, isAscendantOf, isDescendantOf, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotate, scale, scale, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setParent, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setVisible, setWidth, setX, setY, setZIndex, size, size, stageToLocalCoordinates, toBack, toFront, toString, translatepublic TextField(java.lang.String text,
Skin skin)
public TextField(java.lang.String text,
Skin skin,
java.lang.String styleName)
public TextField(java.lang.String text,
TextField.TextFieldStyle style)
public void setMaxLength(int maxLength)
public int getMaxLength()
public void setStyle(TextField.TextFieldStyle style)
public void setPasswordCharacter(char passwordCharacter)
public TextField.TextFieldStyle getStyle()
setStyle(TextFieldStyle)
is called.public void draw(SpriteBatch batch, float parentAlpha)
WidgetWidget.validate() should be called to ensure the widget is laid out.public void copy()
Clipboard implementation set on this TextField.public void cut()
Clipboard implementation set on this TextField, then removes
it.public void next(boolean up)
up - If true, the TextField with the same or next smallest y coordinate is found, else the next highest.public void setTextFieldListener(TextField.TextFieldListener listener)
listener - May be null.public void setTextFieldFilter(TextField.TextFieldFilter filter)
filter - May be null.public void setFocusTraversal(boolean focusTraversal)
public java.lang.String getMessageText()
public void setMessageText(java.lang.String messageText)
messageText - may be null.public void setText(java.lang.String text)
public java.lang.String getText()
public void setSelection(int selectionStart,
int selectionEnd)
public void selectAll()
public void clearSelection()
public void setCursorPosition(int cursorPosition)
public int getCursorPosition()
public TextField.OnscreenKeyboard getOnscreenKeyboard()
TextField.DefaultOnscreenKeyboard.public void setOnscreenKeyboard(TextField.OnscreenKeyboard keyboard)
public void setClipboard(Clipboard clipboard)
public float getPrefWidth()
getPrefWidth in interface LayoutgetPrefWidth in class Widgetpublic float getPrefHeight()
getPrefHeight in interface LayoutgetPrefHeight in class Widgetpublic void setRightAligned(boolean rightAligned)
public void setPasswordMode(boolean passwordMode)
public void setBlinkTime(float blinkTime)
public void setDisabled(boolean disabled)
public boolean isDisabled()
public boolean isPasswordMode()
public TextField.TextFieldFilter getTextFieldFilter()