Class TextField
- All Implemented Interfaces:
Cullable,Disableable,Layout
- Direct Known Subclasses:
TextArea,TextFieldXPlatform
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.
- Author:
- mzechner, Nathan Sweet
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassstatic classThe defaultTextField.OnscreenKeyboardused by allTextFieldinstances.static interfaceAn interface for onscreen keyboards.classBasic input listener for the text fieldstatic interfaceInterface for filtering characters entered into the text field.static interfaceInterface for listening to typed characters.static classThe style for a text field, seeTextField. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic floatstatic floatbooleanboolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidappendText(String str) voidvoidcopy()Copies the contents of this TextField to theClipboardimplementation set on this TextField.voidcut()Copies the selected contents of this TextField to theClipboardimplementation set on this TextField, then removes it.voidIf this method is overridden, the super method orWidgetGroup.validate()should be called to ensure the widget group is laid out.intintfloatfloatbooleanintDefault is an instance ofTextField.DefaultOnscreenKeyboard.floatfloatbooleanvoidintgetStyle()Returns the text field's style.getText()booleanbooleanintletterUnderCursor(float x) voidnext(boolean up) Sets thekeyboard focusto the next TextField.voidvoidsetAlignment(int alignment) Sets text horizontal alignment (left, center or right).voidsetBlinkTime(float blinkTime) voidsetClipboard(Clipboard clipboard) voidsetCursorPosition(int cursorPosition) Sets the cursor position and clears any selection.voidsetDisabled(boolean disabled) voidsetFocusTraversal(boolean focusTraversal) If true (the default), tab/shift+tab will move to the next text field.voidsetMaxLength(int maxLength) voidsetMessageText(String messageText) Sets the text that will be drawn in the text field if no text has been entered.voidsetOnlyFontChars(boolean onlyFontChars) When false, text set bysetText(String)may contain characters not in the font, a space will be displayed instead.voidvoidsetPasswordCharacter(char passwordCharacter) Sets the password character for the text field.voidsetPasswordMode(boolean passwordMode) If true, the text in this text field will be shown as bullet characters.voidsetProgrammaticChangeEvents(boolean programmaticChangeEvents) If false, methods that change the text will not fireChangeListener.ChangeEvent, the event will be fired only when the user changes the text.voidsetSelection(int selectionStart, int selectionEnd) Sets the selected text.voidsetStyle(TextField.TextFieldStyle style) voidvoidvoidvoidMethods inherited from class com.prineside.tdi2.scene2d.ui.WidgetGroup
getMaxHeight, getMaxHeightValue, getMaxWidth, getMaxWidthValue, getMinHeight, getMinHeightValue, getMinWidth, getMinWidthValue, getPrefHeightValue, getPrefWidthValue, hit, invalidate, invalidateHierarchy, layout, needsLayout, pack, setFillParent, setLayoutEnabled, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setPrefHeight, setPrefHeight, setPrefWidth, setPrefWidth, setWidth, validateMethods inherited from class com.prineside.tdi2.scene2d.Group
act, addActor, addActorAfter, addActorAt, addActorBefore, clear, clear, clearChildren, clearChildren, debugAll, drawDebug, findActor, getChild, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, removeActor, removeActor, removeActorAt, setCullingArea, setDebug, setTransform, swapActor, swapActor, toStringMethods inherited from class com.prineside.tdi2.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
-
Field Details
-
keyRepeatInitialTime
public static float keyRepeatInitialTime -
keyRepeatTime
public static float keyRepeatTime -
writeEnters
public boolean writeEnters -
replaceTabsWithSpaces
public boolean replaceTabsWithSpaces
-
-
Constructor Details
-
TextField
-
-
Method Details
-
letterUnderCursor
public int letterUnderCursor(float x) -
setMaxLength
public void setMaxLength(int maxLength) -
getMaxLength
public int getMaxLength() -
setOnlyFontChars
public void setOnlyFontChars(boolean onlyFontChars) When false, text set bysetText(String)may contain characters not in the font, a space will be displayed instead. When true (the default), characters not in the font are stripped by setText. Characters not in the font are always stripped when typed or pasted. -
setStyle
-
getStyle
Returns the text field's style. Modifying the returned style may not have an effect untilsetStyle(TextFieldStyle)is called. -
draw
Description copied from class:WidgetGroupIf this method is overridden, the super method orWidgetGroup.validate()should be called to ensure the widget group is laid out.- Overrides:
drawin classWidgetGroupparentAlpha- The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
-
getSelectionBoundingBox
-
getCursorX
public float getCursorX() -
getCursorY
public float getCursorY() -
copy
public void copy()Copies the contents of this TextField to theClipboardimplementation set on this TextField. -
cut
public void cut()Copies the selected contents of this TextField to theClipboardimplementation set on this TextField, then removes it. -
next
public void next(boolean up) Sets thekeyboard focusto the next TextField. If no next text field is found, the onscreen keyboard is hidden. Does nothing if the text field is not in a stage.- Parameters:
up- If true, the text field with the same or next smallest y coordinate is found, else the next highest.
-
getDefaultInputListener
-
setTextFieldListener
- Parameters:
listener- May be null.
-
setTextFieldFilter
- Parameters:
filter- May be null.
-
getTextFieldFilter
-
setFocusTraversal
public void setFocusTraversal(boolean focusTraversal) If true (the default), tab/shift+tab will move to the next text field. -
getFocusTraversal
public boolean getFocusTraversal() -
getMessageText
- Returns:
- May be null.
-
setMessageText
Sets the text that will be drawn in the text field if no text has been entered.- Parameters:
messageText- may be null.
-
appendText
- Parameters:
str- If null, "" is used.
-
setText
- Parameters:
str- If null, "" is used.
-
getText
- Returns:
- Never null, might be an empty string.
-
setProgrammaticChangeEvents
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents) If false, methods that change the text will not fireChangeListener.ChangeEvent, the event will be fired only when the user changes the text. -
getProgrammaticChangeEvents
public boolean getProgrammaticChangeEvents() -
getSelectionStart
public int getSelectionStart() -
getSelection
-
setSelection
public void setSelection(int selectionStart, int selectionEnd) Sets the selected text. -
selectAll
public void selectAll() -
clearSelection
public void clearSelection() -
updateContextMenu
public void updateContextMenu() -
setCursorPosition
public void setCursorPosition(int cursorPosition) Sets the cursor position and clears any selection. -
getCursorPosition
public int getCursorPosition() -
getOnscreenKeyboard
Default is an instance ofTextField.DefaultOnscreenKeyboard. -
setOnscreenKeyboard
-
setClipboard
-
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidthin interfaceLayout- Overrides:
getPrefWidthin classWidgetGroup
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeightin interfaceLayout- Overrides:
getPrefHeightin classWidgetGroup
-
setAlignment
public void setAlignment(int alignment) Sets text horizontal alignment (left, center or right).- See Also:
-
getAlignment
public int getAlignment() -
setPasswordMode
public void setPasswordMode(boolean passwordMode) If true, the text in this text field will be shown as bullet characters.- See Also:
-
isPasswordMode
public boolean isPasswordMode() -
setPasswordCharacter
public void setPasswordCharacter(char passwordCharacter) Sets the password character for the text field. The character must be present in theBitmapFont. Default is 149 (bullet). -
setBlinkTime
public void setBlinkTime(float blinkTime) -
setDisabled
public void setDisabled(boolean disabled) - Specified by:
setDisabledin interfaceDisableable
-
isDisabled
public boolean isDisabled()- Specified by:
isDisabledin interfaceDisableable
-