APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.ui

public Class TextField

extends Widget
implements Disableable, Styleable<TextField.TextFieldStyle>
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.ui.Styleable, com.badlogic.gdx.scenes.scene2d.utils.Disableable
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.TextArea
Imports
com.badlogic.gdx.Gdx, .Input, .Input.Keys, .Input.OnscreenKeyboardType, com.badlogic.gdx.graphics.Color, com.badlogic.gdx.graphics.g2d.Batch, .BitmapFont, .BitmapFont.BitmapFontData, .GlyphLayout, .GlyphLayout.GlyphRun, com.badlogic.gdx.input.NativeInputConfiguration, .TextInputWrapper, com.badlogic.gdx.math.MathUtils, .Vector2, com.badlogic.gdx.scenes.scene2d.Actor, .Group, .InputEvent, .InputListener, .Stage, com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent, .ClickListener, .Disableable, .Drawable, .UIUtils, com.badlogic.gdx.utils.Align, .Array, .Clipboard, .FloatArray, .Null, .Queue, .Timer, .Timer.Task

A single-line text input field.

The preferred height of a text field is the height of the TextFieldStyle#font and 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 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 OnscreenKeyboard implementation will bring up the default IME.

Authors
mzechner, Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
pack-priv class
public static class
public static interface
TextField.OnscreenKeyboard

An interface for onscreen keyboards.

public class
TextField.TextFieldClickListener

Basic input listener for the text field

public static interface
TextField.TextFieldFilter

Interface for filtering characters entered into the text field.

public static interface
TextField.TextFieldListener

Interface for listening to typed characters.

public static class
TextField.TextFieldStyle

The style for a text field, see TextField.

pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private String[]
protected static final char
pack-priv final Timer.Task
pack-priv float
protected static final char
BULLET

This is the default char used in password fields, a Unicode bullet at code point 0x2022.

protected static final char
pack-priv Clipboard
protected int
pack-priv boolean
public static TextField.OnscreenKeyboard
protected static final char
pack-priv boolean
protected CharSequence
pack-priv TextField.TextFieldFilter
pack-priv boolean
pack-priv boolean
protected float
protected final FloatArray
protected boolean
pack-priv InputListener
pack-priv TextField.OnscreenKeyboard
private Input.OnscreenKeyboardType
public static float
pack-priv final TextField.KeyRepeatTask
public static float
protected final GlyphLayout
pack-priv TextField.TextFieldListener
private int
private String
protected static final char
pack-priv boolean
private StringBuilder
private char
pack-priv boolean
private boolean
pack-priv boolean
pack-priv float
protected int
private float
private float
pack-priv TextField.TextFieldStyle
protected static final char
protected String
private int
protected float
protected float
private static final Vector2
private static final Vector2
private static final Vector2
private final TextField.Undo
public static int
protected int
protected int
protected boolean

Constructor Summary

AccessConstructor and Description
public
TextField(String text, Skin skin)

public
TextField(String text, Skin skin, String styleName)

public

Method Summary

Modifier and TypeMethod and Description
public void
appendText(String
If null, "" is used.
str
)

protected void
pack-priv boolean
changeText(String oldText, String newText)

Returns: True if the text was changed.

public void
protected boolean
continueCursor(int index, int offset)

public void
copy()

Copies the contents of this TextField to the Clipboard implementation set on this TextField.

protected InputListener
public void
cut()

Copies the selected contents of this TextField to the Clipboard implementation set on this TextField, then removes it.

pack-priv void
cut(boolean fireChangeEvent)

pack-priv int
delete(boolean fireChangeEvent)

public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

protected void
drawBackground(Drawable background, Batch batch, float x, float y, float width, float height)

protected void
drawCursor(Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y)

protected void
drawMessageText(Batch batch, BitmapFont font, float x, float y, float maxWidth)

protected void
drawSelection(Drawable selection, Batch batch, BitmapFont font, float x, float y)

Draws selection rectangle

protected void
drawText(Batch batch, BitmapFont font, float x, float y)

private TextField
findNextTextField(Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up)

Returns: May be null.

public int
protected Drawable
public int
public InputListener
public boolean
public int
public String
getMessageText()

Returns: May be null.

public TextField.OnscreenKeyboard
getOnscreenKeyboard()

Default is an instance of DefaultOnscreenKeyboard.

public float
public float
public boolean
public String
public int
public TextField.TextFieldStyle
getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the text field's style.

public String
getText()

Returns: Never null, might be an empty string.

public TextField.TextFieldFilter
protected float
getTextY(BitmapFont font, Drawable background)

protected void
pack-priv String
insert(int position, CharSequence text, String to)

public boolean
public boolean
protected boolean
protected int
protected void
moveCursor(boolean forward, boolean jump)

public TextField

Returns:

The textfield, the focus has been transferred too
next
(boolean
If true, the text field with the same or next smallest y coordinate is found, else the next highest.
up
)

Sets the keyboard focus to the next TextField.

pack-priv void
paste(String content, boolean fireChangeEvent)

public void
redo()

Restores the next text and selection history state.

pack-priv void
redo(boolean fireChangeEvent)

public void
public void
setAlignment(int alignment)

Sets text horizontal alignment (left, center or right).

public void
setAutocompleteOptions(String[] autocompleteOptions)

A list of possible strings that are valid to autocomplete Currently only has an effect on mobile with NativeOnscreenKeyboard

public void
setBlinkTime(float blinkTime)

public void
public void
setCursorPosition(int cursorPosition)

Sets the cursor position and clears any selection.

public void
public void
setFocusTraversal(boolean focusTraversal)

If true (the default), tab/shift+tab will move to the next text field.

public void
public void
setMaxLength(int maxLength)

public void
setMessageText(String
may be null.
messageText
)

Sets the text that will be drawn in the text field if no text has been entered.

public void
setOnlyFontChars(boolean onlyFontChars)

When false, text set by setText(String) may contain characters not in the font, a space will be displayed instead.

public void
public void
setPasswordCharacter(char passwordCharacter)

Sets the password character for the text field.

public void
setPasswordMode(boolean passwordMode)

If true, the text in this text field will be shown as bullet characters.

public void
setPreventAutoCorrection(boolean preventAutoCorrection)

Whether if auto correction is provided by the system, it should be surpressed Will be considered true, if OnscreenKeyboardType is `Password`

public void
setProgrammaticChangeEvents(boolean programmaticChangeEvents)

If false, methods that change the text will not fire ChangeEvent, the event will be fired only when the user changes the text.

public void
setSelection(int selectionStart, int selectionEnd)

Sets the selected text.

public void
setStyle(TextField.TextFieldStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

public void
setText(String
If null, "" is used.
str
)

public void
public void
public void
undo()

Restores the previous text and selection history state.

pack-priv void
undo(boolean fireChangeEvent)

protected void
pack-priv boolean
withinMaxLength(int size)

protected int[]
pack-priv int[]
wordUnderCursor(float x)

Inherited from com.badlogic.gdx.scenes.scene2d.ui.Widget:
getMaxHeightgetMaxWidthgetMinHeightgetMinWidthinvalidateinvalidateHierarchylayoutneedsLayoutpacksetFillParentsetLayoutEnabledsizeChangedvalidate