public class TextArea
ImplementsActionSource, Animation, Editable, StyleListener, TextHolder
Known subtypesTextField
An optionally multi-line editable region that can display text and allow a user to edit it. By default the text area will grow based on its content.
TextArea is useful both for text input and for displaying multi-line data, it is used internally
by components such as com.codename1.components.SpanLabel &
com.codename1.components.SpanButton.
TextArea & com.codename1.ui.TextField are very similar, we discuss the main differences
between the two here. In fact they are so similar that our sample code
below was written for com.codename1.ui.TextField but should be interchangeable with TextArea.
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);
Fields
public static final int ANY = 0 | Allows any type of input into a text field, if a constraint is not supported by an underlying implementation this will be the default. |
public static final int EMAILADDR = 1 | The user is allowed to enter an e-mail address. |
public static final int NUMERIC = 2 | The user is allowed to enter only an integer value. |
public static final int PHONENUMBER = 3 | The user is allowed to enter a phone number. |
public static final int URL = 4 | The user is allowed to enter a URL. |
public static final int DECIMAL = 5 | The user is allowed to enter numeric values with optional decimal fractions, for example “-123”, “0.123”, or “.5”. |
public static final int PASSWORD = 65536 | Indicates that the text entered is confidential data that should be obscured whenever possible. |
public static final int UNEDITABLE = 131072 | Indicates that editing is currently disallowed. |
public static final int SENSITIVE = 262144 | Indicates that the text entered is sensitive data that the implementation must never store into a dictionary or table for use in predictive, auto-completing, or other accelerated input schemes. |
public static final int NON_PREDICTIVE = 524288 | Indicates that the text entered does not consist of words that are likely to be found in dictionaries typically used by predictive input schemes. |
public static final int INITIAL_CAPS_WORD = 1048576 | This flag is a hint to the implementation that during text editing, the initial letter of each word should be capitalized. |
public static final int INITIAL_CAPS_SENTENCE = 2097152 | This flag is a hint to the implementation that during text editing, the initial letter of each sentence should be capitalized. |
public static final int USERNAME = 4194304 | This flag is a hint to the implementation that this field contains a username. |
public static final int UPPERCASE = 8388608 | This flag is a hint to the implementation that the text in this field should be upper case |
public static final int ONE_TIME_CODE = 16777216 | This flag is a hint to the implementation that this field holds a one-time code the user received out of band, typically by SMS. |
Constructors
public TextArea(int rows, int columns) | Creates an area with the given rows and columns |
public TextArea(int rows, int columns, int constraint) | Creates an area with the given rows, columns and constraint |
public TextArea(String text, int rows, int columns) | Creates an area with the given text, rows and columns |
public TextArea(String text, int rows, int columns, int constraint) | Creates an area with the given text, rows, columns and constraint |
public TextArea(String text, int maxSize) | Creates an area with the given text and maximum size, this constructor will create a single line text area similar to a text field! |
public TextArea(String text) | Creates an area with the given text, this constructor will create a single line text area similar to a text field! |
public TextArea() | Creates an empty text area, this constructor will create a single line text area similar to a text field! |
Methods
public static int getDefaultValign() | Indicates the default vertical alignment for a text field. |
public static void setDefaultValign(int aDefaultValign) | Indicates the default vertical alignment for a text field. |
public static void setDefaultMaxSize(int value) | Sets the default limit for the native text box size |
public static boolean isAutoDegradeMaxSize() | Indicates whether a high value for default maxSize will be reduced to a lower value if the underlying platform throws an exception. |
public static void setAutoDegradeMaxSize(boolean value) | Indicates whether a high value for default maxSize will be reduced to a lower value if the underlying platform throws an exception. |
public static char getWidestChar() | Indicates the widest character in the alphabet, this is useful for detecting linebreaks internally. |
public static void setWidestChar(char widestC) | Indicates the widest character in the alphabet, this is useful for detecting linebreaks internally. |
public static void autoDetectWidestChar(String s) | Searches the given string for the widest character using char width, this operation should only be performed once and it solves cases where a devices language might have a char bigger than ‘W’ that isn’t consistently bigger. |
public static boolean isUseStringWidth() | By default text area uses charWidth since its much faster on some devices than string width. |
public static void setUseStringWidth(boolean aUseStringWidth) | By default text area uses charWidth since its much faster on some devices than string width. |
protected void initComponent() | Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state |
protected void deinitialize() | Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. |
protected void initLaf(UIManager uim) | This method initializes the Component defaults constants |
public int getConstraint() | Returns the editing constraint value |
public void setConstraint(int constraint) | Sets the constraint which provides a hint to the virtual keyboard input, notice this doesn’t limit input type in any way! |
public void setWidth(int width) | Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly. |
public String getText() | Returns the text in the text area |
public void setText(String t) | Sets the text within this text area |
public int getAsInt(int invalid) | Convenience method for numeric text fields, returns the value as a number or invalid if the value in the text field isn’t a number |
public long getAsLong(long invalid) | Convenience method for numeric text fields, returns the value as a number or invalid if the value in the text field isn’t a number |
public double getAsDouble(double invalid) | Convenience method for numeric text fields, returns the value as a number or invalid if the value in the text field isn’t a number |
public boolean isEditable() | Returns true if this area is editable |
public void setEditable(boolean b) | Sets this text area to be editable or readonly |
public int getPreferredTabIndex() | Gets the preferred tab index of this component. |
public int getMaxSize() | Returns the maximum size for the text area |
public void setMaxSize(int maxSize) | Sets the maximum size of the text area |
public void keyPressed(int keyCode) | If this Component is focused, the key pressed event will call this method |
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 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. |
public void keyReleased(int keyCode) | If this Component is focused, the key released event will call this method |
public boolean isScrollableY() | Indicates whether the component should/could scroll on the Y axis |
public void pointerHover(int[] x, int[] y) | Invoked for devices where the pointer can hover without actually clicking the display. |
public void pointerHoverReleased(int[] x, int[] y) | Invoked for devices where the pointer can hover without actually clicking the display. |
public void pointerReleased(int x, int y) | If this Component is focused, the pointer released event will call this method |
public int getColumns() | Returns the number of columns in the text area |
public void setColumns(int columns) | Sets the number of columns in the text area |
public int getActualRows() | Returns the number of actual rows in the text area taking into consideration growsByContent |
public int getRows() | Returns the number of rows in the text area |
public void setRows(int rows) | Sets the number of rows in the text area |
public int getLines() | Returns the number of text lines in the TextArea |
public String getTextAt(int line) | Returns the text in the given row of the text box |
protected char[] preprocess(String text) | Override this to modify the text for rendering in cases of invalid characters for display, this method allows the developer to replace such characters e.g.: replace “\t” with 4 spaces |
public int getRowsGap() | Gets the num of pixels gap between the rows |
public void setRowsGap(int rowsGap) | The gap in pixels between rows |
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. |
protected Dimension calcScrollSize() | Method that can be overriden to represent the actual size of the component when it differs from the desireable size for the viewport |
public void addActionListener(ActionListener a) | Add an action listener which is invoked when the text area was modified not during modification. |
public void removeActionListener(ActionListener a) | Removes an action listener |
public void addCloseListener(ActionListener l) | Adds a listener to be called with this TextArea is “closed”. |
public void removeCloseListener(ActionListener l) | Removes close listener. |
public boolean isGrowByContent() | Indicates that the text area should “grow” in height based on the content beyond the limits indicate by the rows variable |
public void setGrowByContent(boolean growByContent) | Indicates that the text area should “grow” in height based on the content beyond the limits indicate by the rows variable |
public String getUnsupportedChars() | Unsupported characters is a string that contains characters that cause issues when rendering on some problematic fonts. |
public void setUnsupportedChars(String unsupportedChars) | Unsupported characters is a string that contains characters that cause issues when rendering on some problematic fonts. |
public int getLinesToScroll() | Indicates the number of lines to scroll with every scroll operation |
public void setLinesToScroll(int linesToScroll) | Indicates the number of lines to scroll with every scroll operation |
public boolean isSingleLineTextArea() | Indicates whether this is a single line text area, in which case “growing” won’t work as expected. |
public void setSingleLineTextArea(boolean singleLineTextArea) | Indicates whether this is a single line text area, in which case “growing” won’t work as expected. |
public int getAlignment() | Deprecated Returns the alignment of the TextArea |
public void setAlignment(int align) | Deprecated Sets the Alignment of the TextArea to one of: CENTER, LEFT, RIGHT |
public int getAbsoluteAlignment() | Deprecated Returns the absolute alignment of the TextArea In RTL LEFT alignment is actually RIGHT, but this method returns the actual alignment |
public boolean isPendingCommit() | Returns true if the text field is waiting for a commit on editing |
public int getCursorPosition() | Returns 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 boolean isQwertyInput() | True is this is a qwerty device or a device that is currently in qwerty mode. |
public String getInputMode() | Returns the currently selected input mode |
public String[] getInputModeOrder() | Returns the order in which input modes are toggled |
public boolean isEnableInputScroll() | Indicates whether text field input should scroll to the right side when no more room for the input is present. |
protected boolean isEnterKey(int keyCode) | Indicates the enter key to be used for editing the text area and by the text field |
public String getHint() | Returns the hint text |
public void setHint(String hint) | Sets the TextArea hint text, the hint text is displayed on the TextArea When there is no text in the TextArea |
public Image getHintIcon() | Returns the hint icon |
public void setHintIcon(Image icon) | Sets the TextArea hint icon, the hint is displayed on the TextArea When there is no text in the TextArea |
public void setHint(String hint, Image icon) | Sets the TextArea hint text and Icon, the hint text and icon are displayed on the TextArea when there is no text in the TextArea |
public Label getHintLabel() | Returns the hint label component that can be customized directly |
public int getVerticalAlignment() | Returns the vertical alignment of the text field, one of: CENTER, TOP, BOTTOM |
public void setVerticalAlignment(int valign) | Sets the vertical alignment of the text field to one of: CENTER, TOP, BOTTOM |
public String[] getBindablePropertyNames() | Returns the names of the properties within this component that can be bound for persistence, the order of these names mean that the first one will be the first bound |
public Class[] getBindablePropertyTypes() | Returns the types of the properties that are bindable within this component |
public void bindProperty(String prop, BindTarget target) | Deprecated Binds the given property name to the given bind target |
public void unbindProperty(String prop, BindTarget target) | Deprecated Removes a bind target from the given property name |
public Object getBoundPropertyValue(String prop) | Allows the binding code to extract the value of the property |
public void setBoundPropertyValue(String prop, Object value) | Sets the value of a bound property within this component, notice that this method MUST NOT fire the property change event when invoked to prevent recursion! |
public int getGrowLimit() | Indicates the maximum number of rows in a text area after it has grown, -1 indicates no limit |
public void setGrowLimit(int growLimit) | Indicates the maximum number of rows in a text area after it has grown, -1 indicates no limit |
public boolean isEndsWith3Points() | If the TextArea text is too long to fit the text to the widget this will add “…” at the last displayable row. |
public void setEndsWith3Points(boolean endsWith3Points) | If the TextArea text is too long to fit the text to the widget this will add “…” at the last displayable row. |
public void registerAsInputDevice() | Deprecated Registers this TextArea as the current input device for the current form. |
public void startEditing() | Launches the text field editing, notice that calling this in a callSerially is generally considered good practice |
public void startEditingAsync() | Launches the text field editing in a callserially call |
public boolean isEditing() | Indicates whether we are currently editing this text area |
public void stopEditing() | Stops text editing of this field if it is being edited |
public void stopEditing(Runnable onFinish) | Stops text editing of this field if it is being edited |
public Style getStyle() | Returns the current Component Style allowing code to draw the current component, you should normally use getUnselected/Pressed/DisabledStyle() and not this method since it will return different values based on component state. |
public void addDataChangedListener(DataChangedListener d) | Adds a listener for data change events it will be invoked for every change made to the text field, notice most platforms will invoke only the DataChangedListener.CHANGED event |
public void removeDataChangedListener(DataChangedListener d) | Removes the listener for data change events |
public void addDataChangeListener(DataChangedListener d) | Deprecated Adds a listener for data change events it will be invoked for every change made to the text field, notice most platforms will invoke only the DataChangedListener.CHANGED event |
public void removeDataChangeListener(DataChangedListener d) | Deprecated Removes the listener for data change events |
public void fireDataChanged(int type, int index) | Alert the TextField listeners the text has been changed on the TextField |
public ActionListener getDoneListener() | Gets the done listener of this TextField. |
public void setDoneListener(ActionListener l) | Sets a Done listener on the TextField - notice this listener will be called only on supported platforms that supports done action on the keyboard |
public void fireDoneEvent() | Fire the done event to done listener |
public void fireDoneEvent(int keyEvent) | |
public boolean isActAsLabel() | This flag indicates that the text area should try to act as a label and try to fix more accurately within it’s bounds this might make it slower as a result |
public void setActAsLabel(boolean actAsLabel) | This flag indicates that the text area should try to act as a label and try to fix more accurately within it’s bounds this might make it slower as a result |
protected boolean shouldRenderComponentSelection() | Special case for text components, if they are editing they should always render the selected state A component can indicate whether it is interested in rendering it’s selection explicitly, this defaults to true in non-touch UI’s and false in touch UI’s except for the case where a user clicks the screen. |
protected TextSelection.Spans calculateTextSelectionSpan(TextSelection sel) | Calculates the spans for the the given text selection. |
public boolean isTextSelectionEnabled() | Returns true if text selection is enabled on this label. |
public void setTextSelectionEnabled(boolean enabled) | Enables text selection on this TextArea. |
public TextSelection.TextSelectionSupport getTextSelectionSupport() | Returns text selection support object for this component. |
Inherited fields
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
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, longKeyPress, keyRepeated, 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, animate, 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
Field details
ANY
public static final int ANY = 0EMAILADDR
public static final int EMAILADDR = 1NUMERIC
public static final int NUMERIC = 2PHONENUMBER
public static final int PHONENUMBER = 3URL
public static final int URL = 4DECIMAL
public static final int DECIMAL = 5PASSWORD
public static final int PASSWORD = 65536UNEDITABLE
public static final int UNEDITABLE = 131072SENSITIVE
public static final int SENSITIVE = 262144NON_PREDICTIVE
public static final int NON_PREDICTIVE = 524288INITIAL_CAPS_WORD
public static final int INITIAL_CAPS_WORD = 1048576INITIAL_CAPS_SENTENCE
public static final int INITIAL_CAPS_SENTENCE = 2097152USERNAME
public static final int USERNAME = 4194304UPPERCASE
public static final int UPPERCASE = 8388608ONE_TIME_CODE
public static final int ONE_TIME_CODE = 16777216This flag is a hint to the implementation that this field holds a one-time code the user received out of band, typically by SMS.
It is the client half of phone number verification: the code is delivered to the device by a message the application never reads, and the platform offers it on a field carrying this hint. On iOS the keyboard’s suggestion bar offers the code from Messages, on Android the autofill service offers it from the SMS. Neither route needs permission to read messages, and neither is available to a field that does not say what it is for – which is what this flag says.
Combine it with #NUMERIC for the usual all digit code. The hint alone
changes no behavior on a platform that cannot offer the code.
See com.codename1.components.OtpField for a field that already carries
this and renders the code one box per digit.
Constructor details
TextArea
public TextArea(int rows, int columns)Parameters
rowsint- the number of rows
columnsint- the number of columns
Throws
IllegalArgumentException- if rows <= 0 or columns <= 1
TextArea
public TextArea(int rows, int columns, int constraint)Parameters
rowsint- the number of rows
columnsint- the number of columns
constraintint- one of ANY, EMAILADDR, NUMERIC, PHONENUMBER, URL, DECIMAL it can be bitwised or’d with one of PASSWORD, UNEDITABLE, SENSITIVE, NON_PREDICTIVE, INITIAL_CAPS_SENTENCE, INITIAL_CAPS_WORD. E.g. ANY | PASSWORD.
Throws
IllegalArgumentException- if rows <= 0 or columns <= 1
TextArea
public TextArea(String text, int rows, int columns)Parameters
textString- the text to be displayed; if text is null, the empty string "" will be displayed
rowsint- the number of rows
columnsint- the number of columns
Throws
IllegalArgumentException- if rows <= 0 or columns <= 1
TextArea
public TextArea(String text, int rows, int columns, int constraint)Parameters
textString- the text to be displayed; if text is null, the empty string "" will be displayed
rowsint- the number of rows
columnsint- the number of columns
constraintint- one of ANY, EMAILADDR, NUMERIC, PHONENUMBER, URL, DECIMAL it can be bitwised or’d with one of PASSWORD, UNEDITABLE, SENSITIVE, NON_PREDICTIVE, INITIAL_CAPS_SENTENCE, INITIAL_CAPS_WORD. E.g. ANY | PASSWORD.
Throws
IllegalArgumentException- if rows <= 0 or columns <= 1
TextArea
public TextArea(String text, int maxSize)Parameters
textString- the text to be displayed; if text is null, the empty string "" will be displayed
maxSizeint- text area maximum size
TextArea
public TextArea(String text)Parameters
textString- the text to be displayed; if text is null, the empty string "" will be displayed
TextArea
public TextArea()Method details
getDefaultValign
public static int getDefaultValign()Returns
setDefaultValign
public static void setDefaultValign(int aDefaultValign)Parameters
aDefaultValignint- the defaultValign to set
setDefaultMaxSize
public static void setDefaultMaxSize(int value)Parameters
valueint- default value for the size of the native text box
isAutoDegradeMaxSize
public static boolean isAutoDegradeMaxSize()Returns
setAutoDegradeMaxSize
public static void setAutoDegradeMaxSize(boolean value)Parameters
valueboolean- new value for autoDegradeMaxSize
getWidestChar
public static char getWidestChar()Returns
setWidestChar
public static void setWidestChar(char widestC)Parameters
widestCchar- the widest character
autoDetectWidestChar
public static void autoDetectWidestChar(String s)Parameters
sString- string to search using charWidth
isUseStringWidth
public static boolean isUseStringWidth()Returns
setUseStringWidth
public static void setUseStringWidth(boolean aUseStringWidth)Parameters
aUseStringWidthboolean- the new value for useStringWidth
initComponent
protected void initComponent()deinitialize
protected void deinitialize()initLaf
protected void initLaf(UIManager uim)getConstraint
public int getConstraint()Returns
See also
setConstraint
public void setConstraint(int constraint)Parameters
constraintint- one of ANY, EMAILADDR, NUMERIC, PHONENUMBER, URL, DECIMAL it can be bitwised or’d with one of PASSWORD, UNEDITABLE, SENSITIVE, NON_PREDICTIVE, INITIAL_CAPS_SENTENCE, INITIAL_CAPS_WORD. E.g. ANY | PASSWORD.
setWidth
public void setWidth(int width)Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.
If a user wishes to affect the component size, setPreferredSize should be used.
Parameters
widthint- the width of the component
getText
public String getText()Returns
setText
public void setText(String t)Parameters
tString- new value for the text area
getAsInt
public int getAsInt(int invalid)Parameters
invalidint- in case the text isn’t an integer this number will be returned
Returns
getAsLong
public long getAsLong(long invalid)Parameters
invalidlong- in case the text isn’t a long this number will be returned
Returns
getAsDouble
public double getAsDouble(double invalid)Parameters
invaliddouble- in case the text isn’t an double this number will be returned
Returns
isEditable
public boolean isEditable()Returns
setEditable
public void setEditable(boolean b)Parameters
bboolean- true is text are is editable; otherwise false
getPreferredTabIndex
public int getPreferredTabIndex()Gets the preferred tab index of this component. Tab indices are used to specify the traversal order when tabbing from component to component in a form.
Tab index meanings work similar to the HTML tabIndex attribute. A tab Index of -1 (the default value) results in the field not being traversable using the keyboard (or using the next/prev buttons in devices’ virtual keyboards). A tab index of 0 results in the component’s traversal order being dictated by the natural traversal order of the form.
Use Form#getTabIterator(com.codename1.ui.Component) to obtain the complete traversal order for
all components in the form.
Best practice is to only explicitly set preferred tabIndex values of 0 if you want the component to be traversable, or -1 if you don’t want the component to be traversable. Explicitly setting a positive preferred tab index may result in unexpected results.
How the Preferred Tab Index is Used
When the user tries to “tab” to the next field (or presses the “Next” button on the virtual keyboard), this
triggers a call to Form#getTabIterator(com.codename1.ui.Component), crawls the component hierarchy and
returns a java.util.ListIterator of all of the traversable fields in the form in the order they should
be traversed. This order is determined by the layout managers on the form. The core layout managers define
sensible traversal orders by default. If you have a custom layout manager, you can override its traversal
order by implementing the com.codename1.ui.layouts.Layout#overridesTabIndices(com.codename1.ui.Container) and
com.codename1.ui.layouts.Layout#getChildrenInTraversalOrder(com.codename1.ui.Container) methods.
Returns
getMaxSize
public int getMaxSize()Returns
setMaxSize
public void setMaxSize(int maxSize)Parameters
maxSizeint- the maximum size of the text area
keyPressed
public void keyPressed(int keyCode)Parameters
keyCodeint- the key code value to indicate a physical key.
fireClicked
protected void fireClicked()isSelectableInteraction
protected boolean isSelectableInteraction()Returns
keyReleased
public void keyReleased(int keyCode)Parameters
keyCodeint- the key code value to indicate a physical key.
isScrollableY
public boolean isScrollableY()Returns
pointerHover
public void pointerHover(int[] x, int[] y)Parameters
xint[]- the pointer x coordinate
yint[]- the pointer y coordinate
pointerHoverReleased
public void pointerHoverReleased(int[] x, int[] y)Parameters
xint[]- the pointer x coordinate
yint[]- the pointer y coordinate
pointerReleased
public void pointerReleased(int x, int y)Parameters
xint- the pointer x coordinate
yint- the pointer y coordinate
getColumns
public int getColumns()Returns
setColumns
public void setColumns(int columns)Parameters
columnsint- number of columns
getActualRows
public int getActualRows()Returns
getRows
public int getRows()Returns
setRows
public void setRows(int rows)Parameters
rowsint- number of rows
getLines
public int getLines()Returns
getTextAt
public String getTextAt(int line)Parameters
lineint- the line number in the text box
Returns
preprocess
protected char[] preprocess(String text)Parameters
textString- the text to process
Returns
getRowsGap
public int getRowsGap()Returns
setRowsGap
public void setRowsGap(int rowsGap)Parameters
rowsGapint- num of pixels to gap between rows
paint
public void paint(Graphics g)Parameters
gGraphics- the component graphics
calcPreferredSize
protected Dimension calcPreferredSize()Returns
calcScrollSize
protected Dimension calcScrollSize()Returns
addActionListener
public void addActionListener(ActionListener a)Parameters
aActionListener- actionListener
removeActionListener
public void removeActionListener(ActionListener a)Parameters
aActionListener- actionListener
addCloseListener
public void addCloseListener(ActionListener l)removeCloseListener
public void removeCloseListener(ActionListener l)isGrowByContent
public boolean isGrowByContent()Returns
setGrowByContent
public void setGrowByContent(boolean growByContent)Parameters
growByContentboolean- true if the text component should grow and false otherwise
getUnsupportedChars
public String getUnsupportedChars()Returns
setUnsupportedChars
public void setUnsupportedChars(String unsupportedChars)Parameters
unsupportedCharsString- the unsupported character string
getLinesToScroll
public int getLinesToScroll()Returns
setLinesToScroll
public void setLinesToScroll(int linesToScroll)Parameters
linesToScrollint- number bigger or equal to 1
isSingleLineTextArea
public boolean isSingleLineTextArea()Returns
setSingleLineTextArea
public void setSingleLineTextArea(boolean singleLineTextArea)Parameters
singleLineTextAreaboolean- set to true to force a single line text
getAlignment
public int getAlignment()Returns
setAlignment
public void setAlignment(int align)Parameters
alignint- alignment value
getAbsoluteAlignment
public int getAbsoluteAlignment()Returns
isPendingCommit
public boolean isPendingCommit()Returns
getCursorPosition
public int getCursorPosition()Returns
getCursorY
public int getCursorY()Returns
getCursorX
public int getCursorX()Returns
isQwertyInput
public boolean isQwertyInput()Returns
getInputMode
public String getInputMode()Returns
getInputModeOrder
public String[] getInputModeOrder()Returns
isEnableInputScroll
public boolean isEnableInputScroll()Returns
isEnterKey
protected boolean isEnterKey(int keyCode)Parameters
keyCodeint- the key tested
getHint
public String getHint()Returns
setHint
public void setHint(String hint)Parameters
hintString- the hint text to display
getHintIcon
public Image getHintIcon()Returns
setHintIcon
public void setHintIcon(Image icon)Parameters
iconImage- the icon
setHint
public void setHint(String hint, Image icon)Parameters
hintString- the hint text to display
iconImage- the hint icon to display
getHintLabel
public Label getHintLabel()Returns
getVerticalAlignment
public int getVerticalAlignment()Returns the vertical alignment of the text field, one of: CENTER, TOP, BOTTOM
Multi-line text areas default to #TOP, regardless of the theme default
(textCmpVAlignInt, which is meant for single-line fields). Single-line fields
keep the theme default. A value passed to #setVerticalAlignment(int) is always
honored as-is, so an explicit #CENTER / #BOTTOM still works (e.g. for display
text). For editable multi-line areas the #TOP default also keeps the lightweight
rendering aligned with the native editor, which top-aligns its content on every
current platform, so the text, cursor and hint don’t jump when editing starts
and ends (issue #5345).
Returns
setVerticalAlignment
public void setVerticalAlignment(int valign)Sets the vertical alignment of the text field to one of: CENTER, TOP, BOTTOM
For multi-line text areas, this alignment is applied only when there is extra vertical space in the component. If there is no extra room, alignment becomes effectively top-aligned because content already fills the available area.
Setting a value here overrides the multi-line #TOP default described in #getVerticalAlignment(): the value you pass is honored even for an editable multi-line area (which may then visibly shift when its native editor, which top-aligns, takes over).
Parameters
valignint- alignment value
getBindablePropertyNames
public String[] getBindablePropertyNames()Returns
getBindablePropertyTypes
public Class[] getBindablePropertyTypes()Returns
bindProperty
public void bindProperty(String prop, BindTarget target)Parameters
propString- the property name
targetBindTarget- the target binder
unbindProperty
public void unbindProperty(String prop, BindTarget target)Parameters
propString- the property names
targetBindTarget- the target binder
getBoundPropertyValue
public Object getBoundPropertyValue(String prop)Parameters
propString- the property
Returns
setBoundPropertyValue
public void setBoundPropertyValue(String prop, Object value)Parameters
propString- the property whose value should be set
valueObject- the value
getGrowLimit
public int getGrowLimit()Returns
setGrowLimit
public void setGrowLimit(int growLimit)Parameters
growLimitint- the growLimit to set
isEndsWith3Points
public boolean isEndsWith3Points()Returns
setEndsWith3Points
public void setEndsWith3Points(boolean endsWith3Points)Parameters
endsWith3Pointsboolean- true if text should add “…” at the end
registerAsInputDevice
public void registerAsInputDevice()startEditing
public void startEditing()startEditingAsync
public void startEditingAsync()isEditing
public boolean isEditing()Returns
stopEditing
public void stopEditing()stopEditing
public void stopEditing(Runnable onFinish)Parameters
onFinishRunnable- invoked when editing stopped
getStyle
public Style getStyle()Returns
super.getStyle() otherwiseaddDataChangedListener
public void addDataChangedListener(DataChangedListener d)Parameters
dDataChangedListener- the listener
removeDataChangedListener
public void removeDataChangedListener(DataChangedListener d)Parameters
dDataChangedListener- the listener
addDataChangeListener
public void addDataChangeListener(DataChangedListener d)Parameters
dDataChangedListener- the listener
removeDataChangeListener
public void removeDataChangeListener(DataChangedListener d)Parameters
dDataChangedListener- the listener
fireDataChanged
public void fireDataChanged(int type, int index)Parameters
typeint- the event type: Added, Removed or Change
indexint- cursor location of the event
getDoneListener
public ActionListener getDoneListener()Returns
setDoneListener
public void setDoneListener(ActionListener l)Parameters
lActionListener- the listener
fireDoneEvent
public void fireDoneEvent()fireDoneEvent
public void fireDoneEvent(int keyEvent)isActAsLabel
public boolean isActAsLabel()Returns
setActAsLabel
public void setActAsLabel(boolean actAsLabel)Parameters
actAsLabelboolean- the actAsLabel to set
shouldRenderComponentSelection
protected boolean shouldRenderComponentSelection()Returns
calculateTextSelectionSpan
protected TextSelection.Spans calculateTextSelectionSpan(TextSelection sel)Parameters
selTextSelection- The TextSelection
isTextSelectionEnabled
public boolean isTextSelectionEnabled()Form#getTextSelection() and TextSelection#setEnabled(boolean),
and also ensure that the label’s text selection is enabled via #setTextSelectionEnabled(boolean).setTextSelectionEnabled
public void setTextSelectionEnabled(boolean enabled)getTextSelectionSupport
public TextSelection.TextSelectionSupport getTextSelectionSupport()