public class TextField

  1. Object
  2. Component
  3. TextArea
  4. TextField

ImplementsActionSource, Animation, Editable, StyleListener, TextHolder

Known subtypesAutoCompleteTextField

A specialized version of com.codename1.ui.TextArea with some minor deviations from the original specifically:

  • Blinking cursor is rendered on TextField only

  • com.codename1.ui.events.DataChangeListener is only available in TextField. This is crucial for character by character input event tracking

  • com.codename1.ui.TextField#setDoneListener(com.codename1.ui.events.ActionListener) is only available in TextField

  • Different UIID’s ("TextField" vs. “TextArea”)

The demo code below shows simple input using text fields:

TableLayout tl;
int spanButton = 2;
if(Display.getInstance().isTablet()) {
    tl = new TableLayout(7, 2);
} else {
    tl = new TableLayout(14, 1);
    spanButton = 1;
}
tl.setGrowHorizontally(true);
hi.setLayout(tl);

TextField firstName = new TextField("", "First Name", 20, TextArea.ANY);
TextField surname = new TextField("", "Surname", 20, TextArea.ANY);
TextField email = new TextField("", "E-Mail", 20, TextArea.EMAILADDR);
TextField url = new TextField("", "URL", 20, TextArea.URL);
TextField phone = new TextField("", "Phone", 20, TextArea.PHONENUMBER);

TextField num1 = new TextField("", "1234", 4, TextArea.NUMERIC);
TextField num2 = new TextField("", "1234", 4, TextArea.NUMERIC);
TextField num3 = new TextField("", "1234", 4, TextArea.NUMERIC);
TextField num4 = new TextField("", "1234", 4, TextArea.NUMERIC);

Button submit = new Button("Submit");
TableLayout.Constraint cn = tl.createConstraint();
cn.setHorizontalSpan(spanButton);
cn.setHorizontalAlign(Component.RIGHT);
hi.add("First Name").add(firstName).
        add("Surname").add(surname).
        add("E-Mail").add(email).
        add("URL").add(url).
        add("Phone").add(phone).
        add("Credit Card").
                add(GridLayout.encloseIn(4, num1, num2, num3, num4)).
        add(cn, submit);

The following code demonstrates a more advanced search widget where the data is narrowed as we type directly into the title area search. Notice that the TextField and its hint are styled to look like the title.

Toolbar.setGlobalToolbar(true);
Form hi = new Form("Toolbar", BoxLayout.y());
Style s = UIManager.getInstance().getComponentStyle("Title");

TextField searchField = new TextField("", "Toolbar Search");
searchField.getHintLabel().setUIID("Title");
searchField.setUIID("Title");
searchField.getAllStyles().setAlignment(Component.LEFT);
hi.getToolbar().setTitleComponent(searchField);

FontImage searchIcon = FontImage.createMaterial(FontImage.MATERIAL_SEARCH, s);
hi.getToolbar().addCommandToRightBar("", searchIcon, e -> searchField.startEditingAsync());

hi.addAll(
        new Label("A Game of Thrones"),
        new Label("A Clash Of Kings"),
        new Label("A Storm Of Swords"),
        new Label("A Feast For Crows"),
        new Label("A Dance With Dragons"));

searchField.addDataChangedListener((type, index) -> {
    String text = searchField.getText().toLowerCase();
    for (Component cmp : hi.getContentPane()) {
        String value = ((Label) cmp).getText().toLowerCase();
        boolean show = text.length() == 0 || value.indexOf(text) > -1;
        cmp.setHidden(!show);
        cmp.setVisible(show);
    }
    hi.getContentPane().animateLayout(250);
});

Constructors

public TextField()Default constructor
public TextField(int columns)Construct a text field with space reserved for columns
public TextField(String text)Construct text field
public TextField(String text, String hint)Construct text field with a hint
public TextField(String text, String hint, int columns, int constraint)Construct text field with a hint, columns and constraint values
public TextField(String text, int columns)Construct text field

Methods

public static boolean isUseNativeTextInput()Deprecated Indicates that native text input should be used in text field when in place editing is supported by the platform
public static void setUseNativeTextInput(boolean aUseNativeTextInput)Deprecated Indicates that native text input should be used in text field when in place editing is supported by the platform
public static void setClearText(String text)Set the text that should appear on the clear softkey
public static void setT9Text(String text)Set the text that should appear on the T9 softkey
public static TextArea create(String text, int columns)Construct text field/area depending on whether native in place editing is supported
public static TextArea create()Default factory method
public static TextArea create(int columns)Construct text field/area depending on whether native in place editing is supported
public static TextArea create(String text)Construct text field/area depending on whether native in place editing is supported
public static void addInputMode(String name, Hashtable values, boolean firstUpcase)Deprecated Adds a new inputmode hashtable with the given name and set of values
public static String[] getDefaultInputModeOrder()Deprecated Returns the order in which input modes are toggled by default
public static void setDefaultInputModeOrder(String[] order)Deprecated Sets the order in which input modes are toggled by default and allows disabling/hiding an input mode
public static char[] getSymbolTable()Returns the symbol table for the device
public static void setSymbolTable(char[] table)Sets the symbol table to show when the user clicks the symbol table key
public static boolean isReplaceMenuDefault()Indicates whether the menu of the form should be replaced with the T9/Clear commands for the duration of interactivity with the text field
public static void setReplaceMenuDefault(boolean replaceMenu)Indicates whether the menu of the form should be replaced with the T9/Clear commands for the duration of interactivity with the text field
public static boolean isQwertyAutoDetect()Indicates whether the text field should try to auto detect qwerty and switch the qwerty device flag implicitly
public static void setQwertyAutoDetect(boolean v)Indicates whether the text field should try to auto detect qwerty and switch the qwerty device flag implicitly
public static boolean isQwertyDevice()The default value for the qwerty flag so it doesn’t need setting for every text field individually.
public static void setQwertyDevice(boolean v)The default value for the qwerty flag so it doesn’t need setting for every text field individually.
public static int getDefaultChangeInputModeKey()Deprecated Key to change the input mode on the device
public static void setDefaultChangeInputModeKey(int k)Deprecated Key to change the input mode on the device
public static int getDefaultSymbolDialogKey()The default key for poping open the symbol dialog
public static void setDefaultSymbolDialogKey(int d)The default key for poping open the symbol dialog
public boolean isEnableInputScroll()Indicates whether text field input should scroll to the right side when no more room for the input is present.
public void setEnableInputScroll(boolean enableInputScroll)Indicates whether text field input should scroll to the right side when no more room for the input is present.
public void deleteChar()Performs a backspace operation
protected void commitChange()Commit the changes made to the text field as a complete edit operation.
public boolean isPendingCommit()Returns true if the text field is waiting for a commit on editing
public int getCommitTimeout()The amount of time in milliseconds it will take for a change to get committed into the field.
public void setCommitTimeout(int commitTimeout)The amount of time in milliseconds it will take for a change to get committed into the field.
public String getInputMode()Deprecated Returns the currently selected input mode
public void setInputMode(String inputMode)Deprecated Sets the current selected input mode matching one of the existing input modes
protected boolean isChangeInputMode(int keyCode)Deprecated Indicates whether the key changes the current input mode
public String[] getInputModeOrder()Returns the order in which input modes are toggled
public void setInputModeOrder(String[] order)Deprecated Sets the order in which input modes are toggled and allows disabling/hiding an input mode
protected String getLongClickInputMode()Returns the input mode for the ong click mode
protected char getCharPerKeyCode(int pressCount, int keyCode, boolean longClick)Returns the character matching the given key code after the given amount of user presses
public int getCursorPosition()Returns the position of the cursor char position
public void setCursorPosition(int pos)Sets the position of the cursor char position
public int getCursorY()Returns the position of the cursor line position
public int getCursorX()Returns the position of the cursor char position in the current line.
public void setText(String text)Sets the text within this text area
public void clear()Clears the text from the TextField
protected boolean isClearKey(int keyCode)Returns true if this is the clear key on the device, many devices don’t contain a clear key and even in those that contain it this might be an issue
protected void longKeyPress(int keyCode)If this Component is focused this method is invoked when the user presses and holds the key
public boolean isQwertyInput()True is this is a qwerty device or a device that is currently in qwerty mode.
public void setQwertyInput(boolean qwerty)True is this is a qwerty device or a device that is currently in qwerty mode.
protected boolean isImmediateInputMode(String mode)Deprecated Returns true if the given input mode should commit immediately or wait for the commit timeout
public void insertChars(String c)Deprecated This method is responsible for adding a character into the field and is the focal point for all input.
public boolean validChar(String c)Checks if the candidate input is valid for this TextField
protected void showSymbolDialog()Invoked to show the symbol dialog, this method can be overriden by subclasses to manipulate the symbol table
protected Container createSymbolTable()Creates a symbol table container used by the showSymbolDialog method.
public void keyReleased(int keyCode)If this Component is focused, the key released event will call this method
protected int getLongClickDuration()The amount of time considered as a “long click” causing the long click method to be invoked.
protected boolean isCursorPositionCycle()Returns true if the cursor should cycle to the beginning of the text when the user navigates beyond the edge of the text and visa versa.
protected boolean isSymbolDialogKey(int keyCode)Returns true if this keycode is the one mapping to the symbol dialog popup
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
public void setEditable(boolean b)Sets this text area to be editable or readonly
public void keyRepeated(int keyCode)If this Component is focused, the key repeat event will call this method.
public void keyPressed(int keyCode)If this Component is focused, the key pressed event will call this method
protected Command installCommands(Command clear, Command t9)Installs the clear and t9 commands onto the parent form, this method can be overriden to provide device specific placement for these commands
protected boolean isSelectableInteraction()This method allows a component to indicate that it is interested in an “implicit” select command to appear in the “fire” button when 3 softbuttons are defined in a device.
protected void fireClicked()When working in 3 softbutton mode “fire” key (center softbutton) is sent to this method in order to allow 3 button devices to work properly.
protected void removeCommands(Command clear, Command t9, Command originalClear)Removes the clear and t9 commands from the parent form, this method can be overriden to provide device specific placement for these commands
protected boolean isEditingTrigger(int keyCode)Indicates whether the given key code should be ignored or should trigger editing, by default fire or any numeric key should trigger editing implicitly.
protected boolean isEditingEndTrigger(int keyCode)Indicates whether the given key code should be ignored or should trigger cause editing to end.
public void paint(Graphics g)This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public int getCursorBlinkTimeOn()The amount of time in milliseconds in which the cursor is visible
public void setCursorBlinkTimeOn(int time)The amount of time in milliseconds in which the cursor is visible
public int getCursorBlinkTimeOff()The amount of time in milliseconds in which the cursor is invisible
public void setCursorBlinkTimeOff(int time)The amount of time in milliseconds in which the cursor is invisible
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
public void pointerReleased(int x, int y)If this Component is focused, the pointer released event will call this method
public boolean isUseSoftkeys()When set to true softkeys are used to enable delete functionality
public void setUseSoftkeys(boolean useSoftkeys)When set to true softkeys are used to enable delete functionality
public boolean isReplaceMenu()Indicates whether the menu of the form should be replaced with the T9/Clear commands for the duration of interactivity with the text field
public void setReplaceMenu(boolean replaceMenu)Indicates whether the menu of the form should be replaced with the T9/Clear commands for the duration of interactivity with the text field
public boolean isOverwriteMode()Indicates that this is the overwrite mode
public void setOverwriteMode(boolean overwriteMode)Indicates that this is the overwrite mode
public boolean isLeftAndRightEditingTrigger()Indicates whether the left/right keys will trigger editing, this is true by default.
public void setLeftAndRightEditingTrigger(boolean leftAndRightEditingTrigger)Indicates whether the left/right keys will trigger editing, this is true by default.
protected TextSelection.Spans calculateTextSelectionSpan(TextSelection sel)Calculates the spans for the the given text selection.

Inherited fields

Inherited methods

From TextArea

getDefaultValign, setDefaultValign, setDefaultMaxSize, isAutoDegradeMaxSize, setAutoDegradeMaxSize, getWidestChar, setWidestChar, autoDetectWidestChar, isUseStringWidth, setUseStringWidth, initComponent, initLaf, getConstraint, setConstraint, setWidth, getText, getAsInt, getAsLong, getAsDouble, isEditable, getPreferredTabIndex, getMaxSize, setMaxSize, isScrollableY, pointerHover, pointerHoverReleased, getColumns, setColumns, getActualRows, getRows, setRows, getLines, getTextAt, preprocess, getRowsGap, setRowsGap, calcScrollSize, addActionListener, removeActionListener, addCloseListener, removeCloseListener, isGrowByContent, setGrowByContent, getUnsupportedChars, setUnsupportedChars, getLinesToScroll, setLinesToScroll, isSingleLineTextArea, setSingleLineTextArea, getAlignment, setAlignment, getAbsoluteAlignment, isEnterKey, getHint, setHint, getHintIcon, setHintIcon, setHint, getHintLabel, getVerticalAlignment, setVerticalAlignment, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getGrowLimit, setGrowLimit, isEndsWith3Points, setEndsWith3Points, registerAsInputDevice, startEditing, startEditingAsync, isEditing, stopEditing, stopEditing, getStyle, addDataChangedListener, removeDataChangedListener, addDataChangeListener, removeDataChangeListener, fireDataChanged, getDoneListener, setDoneListener, fireDoneEvent, fireDoneEvent, isActAsLabel, setActAsLabel, shouldRenderComponentSelection, isTextSelectionEnabled, setTextSelectionEnabled, getTextSelectionSupport

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, stopScrollMomentum, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerPressed, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

TextField

public TextField()
Default constructor

TextField

public TextField(int columns)
Construct a text field with space reserved for columns

Parameters

columns int
  • the number of columns

TextField

public TextField(String text)
Construct text field

Parameters

text String
the text of the field

TextField

public TextField(String text, String hint)
Construct text field with a hint

Parameters

text String
the text of the field
hint String
the hint string

TextField

public TextField(String text, String hint, int columns, int constraint)
Construct text field with a hint, columns and constraint values

Parameters

text String
the text of the field
hint String
the hint string
columns int
columns value
constraint int
the constraint value

TextField

public TextField(String text, int columns)
Construct text field

Parameters

text String
the text of the field
columns int
  • the number of columns

Method details

isUseNativeTextInput

public static boolean isUseNativeTextInput()
Deprecated. this API is no longer useful and should be avoided
Indicates that native text input should be used in text field when in place editing is supported by the platform

Returns

the useNativeTextInput

setUseNativeTextInput

public static void setUseNativeTextInput(boolean aUseNativeTextInput)
Deprecated. this API is no longer useful and should be avoided
Indicates that native text input should be used in text field when in place editing is supported by the platform

Parameters

aUseNativeTextInput boolean
the useNativeTextInput to set

setClearText

public static void setClearText(String text)
Set the text that should appear on the clear softkey

Parameters

text String
localized text for the clear softbutton

setT9Text

public static void setT9Text(String text)
Set the text that should appear on the T9 softkey

Parameters

text String
text for the T9 softbutton

create

public static TextArea create(String text, int columns)
Construct text field/area depending on whether native in place editing is supported

Parameters

text String
the text of the field
columns int
  • the number of columns

Returns

a text field if native in place editing is unsupported and a text area if it is

create

public static TextArea create()
Default factory method

Returns

a text field if native in place editing is unsupported and a text area if it is

create

public static TextArea create(int columns)
Construct text field/area depending on whether native in place editing is supported

Parameters

columns int
  • the number of columns

Returns

a text field if native in place editing is unsupported and a text area if it is

create

public static TextArea create(String text)
Construct text field/area depending on whether native in place editing is supported

Parameters

text String
the text of the field

Returns

a text field if native in place editing is unsupported and a text area if it is

addInputMode

public static void addInputMode(String name, Hashtable values, boolean firstUpcase)
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Adds a new inputmode hashtable with the given name and set of values

Parameters

name String
a unique display name for the input mode e.g. ABC, 123 etc…
values Hashtable
The key for the hashtable is an Integer keyCode and the value is a String containing the characters to toggle between for the given keycode
firstUpcase boolean
indicates if this input mode in an input mode used for the special case where the first letter is an upper case letter

getDefaultInputModeOrder

public static String[] getDefaultInputModeOrder()
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Returns the order in which input modes are toggled by default

Returns

the default order of the input mode

setDefaultInputModeOrder

public static void setDefaultInputModeOrder(String[] order)
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Sets the order in which input modes are toggled by default and allows disabling/hiding an input mode

Parameters

order String[]
the order for the input modes in all future created fields

getSymbolTable

public static char[] getSymbolTable()
Returns the symbol table for the device

Returns

the symbol table of the device for the symbol table input

setSymbolTable

public static void setSymbolTable(char[] table)
Sets the symbol table to show when the user clicks the symbol table key

Parameters

table char[]
the symbol table of the device for the symbol table input

isReplaceMenuDefault

public static boolean isReplaceMenuDefault()
Indicates whether the menu of the form should be replaced with the T9/Clear commands for the duration of interactivity with the text field

Returns

true if the menu should be replaced

setReplaceMenuDefault

public static void setReplaceMenuDefault(boolean replaceMenu)
Indicates whether the menu of the form should be replaced with the T9/Clear commands for the duration of interactivity with the text field

Parameters

replaceMenu boolean
true if the menu should be replaced

isQwertyAutoDetect

public static boolean isQwertyAutoDetect()
Indicates whether the text field should try to auto detect qwerty and switch the qwerty device flag implicitly

Returns

true for qwerty auto detection

setQwertyAutoDetect

public static void setQwertyAutoDetect(boolean v)
Indicates whether the text field should try to auto detect qwerty and switch the qwerty device flag implicitly

Parameters

v boolean
true for qwerty auto detection

isQwertyDevice

public static boolean isQwertyDevice()
The default value for the qwerty flag so it doesn’t need setting for every text field individually.

Returns

true for qwerty devices

setQwertyDevice

public static void setQwertyDevice(boolean v)
The default value for the qwerty flag so it doesn’t need setting for every text field individually.

Parameters

v boolean
true for qwerty device

getDefaultChangeInputModeKey

public static int getDefaultChangeInputModeKey()
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Key to change the input mode on the device

Returns

key to change the input mode

setDefaultChangeInputModeKey

public static void setDefaultChangeInputModeKey(int k)
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Key to change the input mode on the device

Parameters

k int
key to change the input mode

getDefaultSymbolDialogKey

public static int getDefaultSymbolDialogKey()
The default key for poping open the symbol dialog

Returns

the default key

setDefaultSymbolDialogKey

public static void setDefaultSymbolDialogKey(int d)
The default key for poping open the symbol dialog

Parameters

d int
new key value

isEnableInputScroll

public boolean isEnableInputScroll()
Indicates whether text field input should scroll to the right side when no more room for the input is present.

Returns

true if scrolling is enabled

setEnableInputScroll

public void setEnableInputScroll(boolean enableInputScroll)
Indicates whether text field input should scroll to the right side when no more room for the input is present.

Parameters

enableInputScroll boolean
true to enable scrolling to the side

deleteChar

public void deleteChar()
Performs a backspace operation

commitChange

protected void commitChange()
Commit the changes made to the text field as a complete edit operation. This is used in a numeric keypad to allow the user to repeatedly press a number to change values.

isPendingCommit

public boolean isPendingCommit()
Returns true if the text field is waiting for a commit on editing

Returns

true if a commit is pending

getCommitTimeout

public int getCommitTimeout()
The amount of time in milliseconds it will take for a change to get committed into the field.

Returns

the time for a commit timeout

setCommitTimeout

public void setCommitTimeout(int commitTimeout)
The amount of time in milliseconds it will take for a change to get committed into the field.

Parameters

commitTimeout int
indicates the amount of time that should elapse for a commit to automatically occur

getInputMode

public String getInputMode()
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Returns the currently selected input mode

Returns

the display name of the input mode by default the following modes are supported: Abc, ABC, abc, 123

setInputMode

public void setInputMode(String inputMode)
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Sets the current selected input mode matching one of the existing input modes

Parameters

inputMode String
the display name of the input mode by default the following modes are supported: Abc, ABC, abc, 123

isChangeInputMode

protected boolean isChangeInputMode(int keyCode)
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Indicates whether the key changes the current input mode

Parameters

keyCode int
the code

Returns

true for the hash (#) key code

getInputModeOrder

public String[] getInputModeOrder()
Returns the order in which input modes are toggled

Returns

the order of the input modes

setInputModeOrder

public void setInputModeOrder(String[] order)
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Sets the order in which input modes are toggled and allows disabling/hiding an input mode

Parameters

order String[]
the order for the input modes in this field

getLongClickInputMode

protected String getLongClickInputMode()
Returns the input mode for the ong click mode

Returns

returns 123 by default

getCharPerKeyCode

protected char getCharPerKeyCode(int pressCount, int keyCode, boolean longClick)
Returns the character matching the given key code after the given amount of user presses

Parameters

pressCount int
number of times this keycode was pressed
keyCode int
the actual keycode input by the user
longClick boolean
does this click constitute a long click

Returns

the char mapping to this key or 0 if no appropriate char was found (navigation, input mode change etc…).

getCursorPosition

public int getCursorPosition()
Returns the position of the cursor char position

Returns

the cursor position

setCursorPosition

public void setCursorPosition(int pos)
Sets the position of the cursor char position

Parameters

pos int
the cursor position

getCursorY

public int getCursorY()
Returns the position of the cursor line position

Returns

the cursor line position

getCursorX

public int getCursorX()
Returns the position of the cursor char position in the current line.

Returns

the cursor char position in the current line

setText

public void setText(String text)
Sets the text within this text area

Parameters

text String
new value for the text area

clear

public void clear()
Clears the text from the TextField

isClearKey

protected boolean isClearKey(int keyCode)
Returns true if this is the clear key on the device, many devices don’t contain a clear key and even in those that contain it this might be an issue

Parameters

keyCode int
the key code that might be the clear key

Returns

true if this is the clear key.

longKeyPress

protected void longKeyPress(int keyCode)
If this Component is focused this method is invoked when the user presses and holds the key

Parameters

keyCode int
the key code value to indicate a physical key.

isQwertyInput

public boolean isQwertyInput()
True is this is a qwerty device or a device that is currently in qwerty mode.

Returns

currently defaults to false

setQwertyInput

public void setQwertyInput(boolean qwerty)
True is this is a qwerty device or a device that is currently in qwerty mode.

Parameters

qwerty boolean
the value of qwerty mode

isImmediateInputMode

protected boolean isImmediateInputMode(String mode)
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else
Returns true if the given input mode should commit immediately or wait for the commit timeout

Parameters

mode String
the input mode

Returns

returns true for input mode 123 by default

insertChars

public void insertChars(String c)
Deprecated. this is a method for use only on old J2ME devices and is ignored everywhere else

This method is responsible for adding a character into the field and is the focal point for all input. It can be overriden to prevent a particular char from insertion or provide a different behavior for char insertion. It is the responsibility of this method to shift the cursor and invoke setText…

This method accepts a string for the more elaborate cases such as multi-char input and paste.

Parameters

c String
character for insertion

validChar

public boolean validChar(String c)
Checks if the candidate input is valid for this TextField

Parameters

c String
the String to insert

Returns

true if the String is valid

showSymbolDialog

protected void showSymbolDialog()
Invoked to show the symbol dialog, this method can be overriden by subclasses to manipulate the symbol table

createSymbolTable

protected Container createSymbolTable()
Creates a symbol table container used by the showSymbolDialog method. This method is designed for subclases to override and customize.

Returns

container for the symbol table.

keyReleased

public void keyReleased(int keyCode)
If this Component is focused, the key released event will call this method

Parameters

keyCode int
the key code value to indicate a physical key.

getLongClickDuration

protected int getLongClickDuration()
The amount of time considered as a “long click” causing the long click method to be invoked.

Returns

currently defaults to 800

isCursorPositionCycle

protected boolean isCursorPositionCycle()
Returns true if the cursor should cycle to the beginning of the text when the user navigates beyond the edge of the text and visa versa.

Returns

true by default

isSymbolDialogKey

protected boolean isSymbolDialogKey(int keyCode)
Returns true if this keycode is the one mapping to the symbol dialog popup

Parameters

keyCode int
the keycode to check

Returns

true if this is the star symbol *

deinitialize

protected void deinitialize()
Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.

setEditable

public void setEditable(boolean b)
Sets this text area to be editable or readonly

Parameters

b boolean
true is text are is editable; otherwise false

keyRepeated

public void keyRepeated(int keyCode)
If this Component is focused, the key repeat event will call this method.

Parameters

keyCode int
the key code value to indicate a physical key.

keyPressed

public void keyPressed(int keyCode)
If this Component is focused, the key pressed event will call this method

Parameters

keyCode int
the key code value to indicate a physical key.

installCommands

protected Command installCommands(Command clear, Command t9)
Installs the clear and t9 commands onto the parent form, this method can be overriden to provide device specific placement for these commands

Parameters

clear Command
the clear command
t9 Command
the t9 command

Returns

clear command already installed in the form if applicable, none if no clear command was installed before or not applicable.

isSelectableInteraction

protected boolean isSelectableInteraction()
This method allows a component to indicate that it is interested in an “implicit” select command to appear in the “fire” button when 3 softbuttons are defined in a device.

Returns

true if this is a selectable interaction

fireClicked

protected void fireClicked()
When working in 3 softbutton mode “fire” key (center softbutton) is sent to this method in order to allow 3 button devices to work properly. When overriding this method you should also override isSelectableInteraction to indicate that a command is placed appropriately on top of the fire key for 3 soft button phones.

removeCommands

protected void removeCommands(Command clear, Command t9, Command originalClear)
Removes the clear and t9 commands from the parent form, this method can be overriden to provide device specific placement for these commands

Parameters

clear Command
the clear command
t9 Command
the t9 command
originalClear Command
the command originally assigned as the clear command (or null if no command was assigned before)

isEditingTrigger

protected boolean isEditingTrigger(int keyCode)
Indicates whether the given key code should be ignored or should trigger editing, by default fire or any numeric key should trigger editing implicitly. This method is only called when handles input is false.

Parameters

keyCode int
the keycode passed to the keyPressed method

Returns

true if this key code should cause a switch to editing mode.

isEditingEndTrigger

protected boolean isEditingEndTrigger(int keyCode)
Indicates whether the given key code should be ignored or should trigger cause editing to end. By default the fire key, up or down will trigger the end of editing.

Parameters

keyCode int
the keycode passed to the keyPressed method

Returns

true if this key code should cause a switch to editing mode.

paint

public void paint(Graphics g)
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Parameters

g Graphics
the component graphics

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

getCursorBlinkTimeOn

public int getCursorBlinkTimeOn()
The amount of time in milliseconds in which the cursor is visible

Returns

time for the cursor to stay “on”

setCursorBlinkTimeOn

public void setCursorBlinkTimeOn(int time)
The amount of time in milliseconds in which the cursor is visible

Parameters

time int
for the cursor to stay “on”

getCursorBlinkTimeOff

public int getCursorBlinkTimeOff()
The amount of time in milliseconds in which the cursor is invisible

Returns

time for the cursor to stay “off”

setCursorBlinkTimeOff

public void setCursorBlinkTimeOff(int time)
The amount of time in milliseconds in which the cursor is invisible

Parameters

time int
for the cursor to stay “off”

animate

public boolean animate()
Allows the animation to reduce “repaint” calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

Returns

true if a repaint is desired or false if no repaint is necessary

pointerReleased

public void pointerReleased(int x, int y)
If this Component is focused, the pointer released event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

isUseSoftkeys

public boolean isUseSoftkeys()
When set to true softkeys are used to enable delete functionality

Returns

true if softkeys should be used

setUseSoftkeys

public void setUseSoftkeys(boolean useSoftkeys)
When set to true softkeys are used to enable delete functionality

Parameters

useSoftkeys boolean
true if softkeys should be used

isReplaceMenu

public boolean isReplaceMenu()
Indicates whether the menu of the form should be replaced with the T9/Clear commands for the duration of interactivity with the text field

Returns

true if the menu should be replaced

setReplaceMenu

public void setReplaceMenu(boolean replaceMenu)
Indicates whether the menu of the form should be replaced with the T9/Clear commands for the duration of interactivity with the text field

Parameters

replaceMenu boolean
true if the menu should be replaced

isOverwriteMode

public boolean isOverwriteMode()
Indicates that this is the overwrite mode

Returns

true if input with overwrite characters

setOverwriteMode

public void setOverwriteMode(boolean overwriteMode)
Indicates that this is the overwrite mode

Parameters

overwriteMode boolean
set to true if input with overwrite characters

isLeftAndRightEditingTrigger

public boolean isLeftAndRightEditingTrigger()
Indicates whether the left/right keys will trigger editing, this is true by default. Left and right key edit trigger might be disabled for cases such as text field positioned horizontally one next to the other.

Returns

leftAndRightEditingTrigger Indicates whether the left/right keys will trigger editing

setLeftAndRightEditingTrigger

public void setLeftAndRightEditingTrigger(boolean leftAndRightEditingTrigger)
Indicates whether the left/right keys will trigger editing, this is true by default. Left and right key edit trigger might be disabled for cases such as text field positioned horizontally one next to the other.

Parameters

leftAndRightEditingTrigger boolean
Indicates whether the left/right keys will trigger editing

calculateTextSelectionSpan

protected TextSelection.Spans calculateTextSelectionSpan(TextSelection sel)
Calculates the spans for the the given text selection. This should generally just delegate to the appropriate method in the look and feel for performing the layout calculation.

Parameters

sel TextSelection
The TextSelection