Class TextArea
- All Implemented Interfaces:
Animation, Editable, ActionSource, StyleListener, TextHolder
- Direct Known Subclasses:
TextField
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);
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAllows any type of input into a text field, if a constraint is not supported by an underlying implementation this will be the default.static final intThe user is allowed to enter numeric values with optional decimal fractions, for example "-123", "0.123", or ".5".static final intThe user is allowed to enter an e-mail address.static final intThis flag is a hint to the implementation that during text editing, the initial letter of each sentence should be capitalized.static final intThis flag is a hint to the implementation that during text editing, the initial letter of each word should be capitalized.static final intIndicates that the text entered does not consist of words that are likely to be found in dictionaries typically used by predictive input schemes.static final intThe user is allowed to enter only an integer value.static final intIndicates that the text entered is confidential data that should be obscured whenever possible.static final intThe user is allowed to enter a phone number.static final intIndicates 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.static final intIndicates that editing is currently disallowed.static final intThis flag is a hint to the implementation that the text in this field should be upper casestatic final intThe user is allowed to enter a URL.static final intThis flag is a hint to the implementation that this field contains a username.Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
ConstructorsConstructorDescriptionTextArea()Creates an empty text area, this constructor will create a single line text area similar to a text field!TextArea(int rows, int columns) Creates an area with the given rows and columnsTextArea(int rows, int columns, int constraint) Creates an area with the given rows, columns and constraintCreates an area with the given text, this constructor will create a single line text area similar to a text field!Creates an area with the given text and maximum size, this constructor will create a single line text area similar to a text field!Creates an area with the given text, rows and columnsCreates an area with the given text, rows, columns and constraint -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an action listener which is invoked when the text area was modified not during modification.voidAdds a listener to be called with this TextArea is "closed".voidAdds 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 eventvoidAdds 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 eventstatic voidSearches 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.voidbindProperty(String prop, BindTarget target) Binds the given property name to the given bind targetprotected DimensionCalculates the preferred size based on component content.protected DimensionMethod that can be overriden to represent the actual size of the component when it differs from the desireable size for the viewportprotected TextSelection.SpansCalculates the spans for the the given text selection.protected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.protected voidWhen working in 3 softbutton mode "fire" key (center softbutton) is sent to this method in order to allow 3 button devices to work properly.voidfireDataChanged(int type, int index) Alert the TextField listeners the text has been changed on the TextFieldvoidFire the done event to done listenervoidfireDoneEvent(int keyEvent) intReturns the absolute alignment of the TextArea In RTL LEFT alignment is actually RIGHT, but this method returns the actual alignmentintReturns the number of actual rows in the text area taking into consideration growsByContentintReturns the alignment of the TextAreadoublegetAsDouble(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 numberintgetAsInt(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 numberlonggetAsLong(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 numberString[]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 boundClass[]Returns the types of the properties that are bindable within this componentgetBoundPropertyValue(String prop) Allows the binding code to extract the value of the propertyintReturns the number of columns in the text areaintReturns the editing constraint valueintReturns the position of the cursor char positionintReturns the position of the cursor char position in the current line.intReturns the position of the cursor line positionstatic intIndicates the default vertical alignment for a text field, only applies to single line text fieldsGets the done listener of this TextField.intIndicates the maximum number of rows in a text area after it has grown, -1 indicates no limitgetHint()Returns the hint textReturns the hint iconReturns the hint label component that can be customized directlyReturns the currently selected input modeString[]Returns the order in which input modes are toggledintgetLines()Returns the number of text lines in the TextAreaintIndicates the number of lines to scroll with every scroll operationintReturns the maximum size for the text areaintGets the preferred tab index of this component.intgetRows()Returns the number of rows in the text areaintGets the num of pixels gap between the rowsgetStyle()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.getText()Returns the text in the text areagetTextAt(int line) Returns the text in the given row of the text boxReturns text selection support object for this component.Unsupported characters is a string that contains characters that cause issues when rendering on some problematic fonts.intReturns the vertical alignment of the text field, this only applies to single line text fieldstatic charIndicates the widest character in the alphabet, this is useful for detecting linebreaks internally.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component stateprotected voidThis method initializes the Component defaults constantsbooleanThis 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 resultstatic booleanIndicates whether a high value for default maxSize will be reduced to a lower value if the underlying platform throws an exception.booleanReturns true if this area is editablebooleanIndicates whether we are currently editing this text areabooleanIndicates whether text field input should scroll to the right side when no more room for the input is present.booleanIf the TextArea text is too long to fit the text to the widget this will add "..." at the last displayable row.protected booleanisEnterKey(int keyCode) Indicates the enter key to be used for editing the text area and by the text fieldbooleanIndicates that the text area should "grow" in height based on the content beyond the limits indicate by the rows variablebooleanReturns true if the text field is waiting for a commit on editingbooleanTrue is this is a qwerty device or a device that is currently in qwerty mode.booleanIndicates whether the component should/could scroll on the Y axisprotected booleanThis 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.booleanIndicates whether this is a single line text area, in which case "growing" won't work as expected.booleanReturns true if text selection is enabled on this label.static booleanBy default text area uses charWidth since its much faster on some devices than string width.voidkeyPressed(int keyCode) If this Component is focused, the key pressed event will call this methodvoidkeyReleased(int keyCode) If this Component is focused, the key released event will call this methodvoidThis 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.voidpointerHover(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display.voidpointerHoverReleased(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display.voidpointerReleased(int x, int y) If this Component is focused, the pointer released event will call this methodprotected 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 spacesvoidRegisters this TextArea as the current input device for the current form.voidRemoves an action listenervoidRemoves close listener.voidRemoves the listener for data change eventsvoidRemoves the listener for data change eventsvoidsetActAsLabel(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 resultvoidsetAlignment(int align) Sets the Alignment of the TextArea to one of: CENTER, LEFT, RIGHTstatic voidsetAutoDegradeMaxSize(boolean value) Indicates whether a high value for default maxSize will be reduced to a lower value if the underlying platform throws an exception.voidsetBoundPropertyValue(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!voidsetColumns(int columns) Sets the number of columns in the text areavoidsetConstraint(int constraint) Sets the constraint which provides a hint to the virtual keyboard input, notice this doesn't limit input type in any way!static voidsetDefaultMaxSize(int value) Sets the default limit for the native text box sizestatic voidsetDefaultValign(int aDefaultValign) Indicates the default vertical alignment for a text field, only applies to single line text fieldsvoidSets a Done listener on the TextField - notice this listener will be called only on supported platforms that supports done action on the keyboardvoidsetEditable(boolean b) Sets this text area to be editable or readonlyvoidsetEndsWith3Points(boolean endsWith3Points) If the TextArea text is too long to fit the text to the widget this will add "..." at the last displayable row.voidsetGrowByContent(boolean growByContent) Indicates that the text area should "grow" in height based on the content beyond the limits indicate by the rows variablevoidsetGrowLimit(int growLimit) Indicates the maximum number of rows in a text area after it has grown, -1 indicates no limitvoidSets the TextArea hint text, the hint text is displayed on the TextArea When there is no text in the TextAreavoidSets the TextArea hint text and Icon, the hint text and icon are displayed on the TextArea when there is no text in the TextAreavoidsetHintIcon(Image icon) Sets the TextArea hint icon, the hint is displayed on the TextArea When there is no text in the TextAreavoidsetLinesToScroll(int linesToScroll) Indicates the number of lines to scroll with every scroll operationvoidsetMaxSize(int maxSize) Sets the maximum size of the text areavoidsetRows(int rows) Sets the number of rows in the text areavoidsetRowsGap(int rowsGap) The gap in pixels between rowsvoidsetSingleLineTextArea(boolean singleLineTextArea) Indicates whether this is a single line text area, in which case "growing" won't work as expected.voidSets the text within this text areavoidsetTextSelectionEnabled(boolean enabled) Enables text selection on this TextArea.voidsetUnsupportedChars(String unsupportedChars) Unsupported characters is a string that contains characters that cause issues when rendering on some problematic fonts.static voidsetUseStringWidth(boolean aUseStringWidth) By default text area uses charWidth since its much faster on some devices than string width.voidsetVerticalAlignment(int valign) Sets the vertical alignment of the text field to one of: CENTER, TOP, BOTTOMstatic voidsetWidestChar(char widestC) Indicates the widest character in the alphabet, this is useful for detecting linebreaks internally.voidsetWidth(int width) Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.protected booleanSpecial 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.voidLaunches the text field editing, notice that calling this in a callSerially is generally considered good practicevoidLaunches the text field editing in a callserially callvoidStops text editing of this field if it is being editedvoidstopEditing(Runnable onFinish) Stops text editing of this field if it is being editedvoidunbindProperty(String prop, BindTarget target) Removes a bind target from the given property nameMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, announceForAccessibility, blocksSideSwipe, cancelRepaints, clearClientProperties, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBorder, getBottomGap, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSideGap, getTabIndex, getTensileLength, getTooltip, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHoverPressed, pointerPressed, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVisible, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, showNativeOverlay, stripMarginAndPadding, styleChanged, toImage, toString, updateNativeOverlay, visibleBoundsContains
-
Field Details
-
ANY
public static final int ANYAllows any type of input into a text field, if a constraint is not supported by an underlying implementation this will be the default.- See Also:
-
EMAILADDR
public static final int EMAILADDRThe user is allowed to enter an e-mail address.- See Also:
-
NUMERIC
public static final int NUMERICThe user is allowed to enter only an integer value.- See Also:
-
PHONENUMBER
public static final int PHONENUMBERThe user is allowed to enter a phone number.- See Also:
-
URL
public static final int URLThe user is allowed to enter a URL.- See Also:
-
DECIMAL
public static final int DECIMALThe user is allowed to enter numeric values with optional decimal fractions, for example "-123", "0.123", or ".5".- See Also:
-
PASSWORD
public static final int PASSWORDIndicates that the text entered is confidential data that should be obscured whenever possible.- See Also:
-
UNEDITABLE
public static final int UNEDITABLEIndicates that editing is currently disallowed.- See Also:
-
SENSITIVE
public static final int SENSITIVEIndicates 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.- See Also:
-
NON_PREDICTIVE
public static final int NON_PREDICTIVEIndicates that the text entered does not consist of words that are likely to be found in dictionaries typically used by predictive input schemes.- See Also:
-
INITIAL_CAPS_WORD
public static final int INITIAL_CAPS_WORDThis flag is a hint to the implementation that during text editing, the initial letter of each word should be capitalized.- See Also:
-
INITIAL_CAPS_SENTENCE
public static final int INITIAL_CAPS_SENTENCEThis flag is a hint to the implementation that during text editing, the initial letter of each sentence should be capitalized.- See Also:
-
USERNAME
public static final int USERNAMEThis flag is a hint to the implementation that this field contains a username.- See Also:
-
UPPERCASE
public static final int UPPERCASEThis flag is a hint to the implementation that the text in this field should be upper case- See Also:
-
-
Constructor Details
-
TextArea
public TextArea(int rows, int columns) Creates an area with the given rows and columns
Parameters
-
rows: the number of rows -
columns: - the number of columns
Throws
IllegalArgumentException: if rows <= 0 or columns <= 1
-
-
TextArea
public TextArea(int rows, int columns, int constraint) Creates an area with the given rows, columns and constraint
Parameters
-
rows: the number of rows -
columns: - the number of columns -
constraint: @param constraint 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
Creates an area with the given text, rows and columns
Parameters
-
text: @param text the text to be displayed; if text is null, the empty string "" will be displayed -
rows: the number of rows -
columns: - the number of columns
Throws
IllegalArgumentException: if rows <= 0 or columns <= 1
-
-
TextArea
Creates an area with the given text, rows, columns and constraint
Parameters
-
text: @param text the text to be displayed; if text is null, the empty string "" will be displayed -
rows: the number of rows -
columns: - the number of columns -
constraint: @param constraint 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
Creates an area with the given text and maximum size, this constructor will create a single line text area similar to a text field!
Parameters
-
text: @param text the text to be displayed; if text is null, the empty string "" will be displayed -
maxSize: text area maximum size
-
-
TextArea
Creates an area with the given text, this constructor will create a single line text area similar to a text field!
Parameters
text: @param text the text to be displayed; if text is null, the empty string "" will be displayed
-
TextArea
public TextArea()Creates an empty text area, this constructor will create a single line text area similar to a text field!
-
-
Method Details
-
getDefaultValign
public static int getDefaultValign()Indicates the default vertical alignment for a text field, only applies to single line text fields
Returns
the defaultValign
-
setDefaultValign
public static void setDefaultValign(int aDefaultValign) Indicates the default vertical alignment for a text field, only applies to single line text fields
Parameters
aDefaultValign: the defaultValign to set
-
setDefaultMaxSize
public static void setDefaultMaxSize(int value) Sets the default limit for the native text box size
Parameters
value: default value for the size of the native text box
-
isAutoDegradeMaxSize
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.
Returns
value for autoDegradeMaxSize
-
setAutoDegradeMaxSize
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.
Parameters
value: new value for autoDegradeMaxSize
-
getWidestChar
public static char getWidestChar()Indicates the widest character in the alphabet, this is useful for detecting linebreaks internally. In CJK languages the widest char is different than W hence this functionality is exposed to developers.
Returns
the widest character
-
setWidestChar
public static void setWidestChar(char widestC) Indicates the widest character in the alphabet, this is useful for detecting linebreaks internally. In CJK languages the widest char is different than W hence this functionality is exposed to developers.
Parameters
widestC: the widest character
-
autoDetectWidestChar
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. Notice that this method will use the TextArea style font which might differ when switching themes etc.
Parameters
s: string to search using charWidth
-
isUseStringWidth
public static boolean isUseStringWidth()By default text area uses charWidth since its much faster on some devices than string width. However, with some fonts and especially some languages (such as Arabic, Korean etc.) the width of the string drawn might not equal the summary of the width of the chars. Hence for portability to those languages/fonts this flag must be set to true.
Returns
the value of useStringWidth
-
setUseStringWidth
public static void setUseStringWidth(boolean aUseStringWidth) By default text area uses charWidth since its much faster on some devices than string width. However, with some fonts and especially some languages (such as Arabic, Korean etc.) the width of the string drawn might not equal the summary of the width of the chars. Hence for portability to those languages/fonts this flag must be set to true.
Parameters
aUseStringWidth: the new value for useStringWidth
-
initComponent
protected void initComponent()Description copied from class:ComponentAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classComponent
-
deinitialize
protected void deinitialize()Description copied from class:ComponentInvoked 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.- Overrides:
deinitializein classComponent
-
initLaf
-
getConstraint
public int getConstraint()Returns the editing constraint value
Returns
the editing constraint value
See also
- #setConstraint
-
setConstraint
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!
Parameters
constraint: @param constraint 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
width: the width of the component
See also
- #setPreferredSize
-
getText
Returns the text in the text area
Returns
the text in the text area
- Specified by:
getTextin interfaceTextHolder
-
setText
Sets the text within this text area
Parameters
t: new value for the text area
- Specified by:
setTextin interfaceTextHolder
-
getAsInt
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
Parameters
invalid: in case the text isn't an integer this number will be returned
Returns
the int value of the text field
-
getAsLong
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
Parameters
invalid: in case the text isn't a long this number will be returned
Returns
the long value of the text field
-
getAsDouble
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
Parameters
invalid: in case the text isn't an double this number will be returned
Returns
the double value of the text field
-
isEditable
public boolean isEditable()Returns true if this area is editable
Returns
true if this area is editable
- Specified by:
isEditablein interfaceEditable- Overrides:
isEditablein classComponent
-
setEditable
public void setEditable(boolean b) Sets this text area to be editable or readonly
Parameters
b: true is text are is editable; otherwise false
-
getPreferredTabIndex
public int getPreferredTabIndex()Description copied from class:ComponentGets 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 ajava.util.ListIteratorof 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 thecom.codename1.ui.layouts.Layout#overridesTabIndices(com.codename1.ui.Container)andcom.codename1.ui.layouts.Layout#getChildrenInTraversalOrder(com.codename1.ui.Container)methods.Returns
the tabbing index
- Overrides:
getPreferredTabIndexin classComponent
-
getMaxSize
public int getMaxSize()Returns the maximum size for the text area
Returns
the maximum size for the text area
-
setMaxSize
public void setMaxSize(int maxSize) Sets the maximum size of the text area
Parameters
maxSize: the maximum size of the text area
-
keyPressed
public void keyPressed(int keyCode) If this Component is focused, the key pressed event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyPressedin classComponent
-
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.- Overrides:
fireClickedin classComponent
-
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
- Overrides:
isSelectableInteractionin classComponent
-
keyReleased
public void keyReleased(int keyCode) If this Component is focused, the key released event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyReleasedin classComponent
-
isScrollableY
public boolean isScrollableY()Indicates whether the component should/could scroll on the Y axis
Returns
whether the component is scrollable on the X axis
- Overrides:
isScrollableYin classComponent
-
pointerHover
public void pointerHover(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerHoverin classComponent
-
-
pointerHoverReleased
public void pointerHoverReleased(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerHoverReleasedin classComponent
-
-
pointerReleased
public void pointerReleased(int x, int y) If this Component is focused, the pointer released event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerReleasedin classComponent
-
-
getColumns
public int getColumns()Returns the number of columns in the text area
Returns
the number of columns in the text area
-
setColumns
public void setColumns(int columns) Sets the number of columns in the text area
Parameters
columns: number of columns
-
getActualRows
public int getActualRows()Returns the number of actual rows in the text area taking into consideration growsByContent
Returns
the number of rows in the text area
-
getRows
public int getRows()Returns the number of rows in the text area
Returns
the number of rows in the text area
-
setRows
public void setRows(int rows) Sets the number of rows in the text area
Parameters
rows: number of rows
-
getLines
public int getLines()Returns the number of text lines in the TextArea
Returns
the number of text lines in the TextArea
-
getTextAt
Returns the text in the given row of the text box
Parameters
line: the line number in the text box
Returns
the text of the line
-
preprocess
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
Parameters
text: the text to process
Returns
the given string as a processed char array ready for rendering
-
getRowsGap
public int getRowsGap()Gets the num of pixels gap between the rows
Returns
the gap between rows in pixels
-
setRowsGap
public void setRowsGap(int rowsGap) The gap in pixels between rows
Parameters
rowsGap: num of pixels to gap between rows
-
paint
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: the component graphics
-
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
- Overrides:
calcPreferredSizein classComponent
-
calcScrollSize
Method that can be overriden to represent the actual size of the component when it differs from the desireable size for the viewport
Returns
scroll size, by default this is the same as the preferred size
- Overrides:
calcScrollSizein classComponent
-
addActionListener
Add an action listener which is invoked when the text area was modified not during modification. A text field might never fire an action event if it is edited in place and the user never leaves the text field!
Parameters
a: actionListener
- Specified by:
addActionListenerin interfaceActionSource
-
removeActionListener
Removes an action listener
Parameters
a: actionListener
- Specified by:
removeActionListenerin interfaceActionSource
-
addCloseListener
Adds a listener to be called with this TextArea is "closed". I.e. when it is no longer the active virtual input device for the form.
Parameters
l
See also
- Form#setCurrentInputDevice(com.codename1.ui.VirtualInputDevice)
-
removeCloseListener
Removes close listener.
Parameters
l
See also
-
#addCloseListener(com.codename1.ui.events.ActionListener)
-
Form#setCurrentInputDevice(com.codename1.ui.VirtualInputDevice)
-
isGrowByContent
public boolean isGrowByContent()Indicates that the text area should "grow" in height based on the content beyond the limits indicate by the rows variable
Returns
true if the text component should grow and false otherwise
-
setGrowByContent
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
Parameters
growByContent: true if the text component should grow and false otherwise
-
getUnsupportedChars
Unsupported characters is a string that contains characters that cause issues when rendering on some problematic fonts. The rendering engine can thus remove them when drawing.
Returns
unsupported characters string
-
setUnsupportedChars
Unsupported characters is a string that contains characters that cause issues when rendering on some problematic fonts. The rendering engine can thus remove them when drawing.
Parameters
unsupportedChars: the unsupported character string
-
getLinesToScroll
public int getLinesToScroll()Indicates the number of lines to scroll with every scroll operation
Returns
number bigger or equal to 1
-
setLinesToScroll
public void setLinesToScroll(int linesToScroll) Indicates the number of lines to scroll with every scroll operation
Parameters
linesToScroll: number bigger or equal to 1
-
isSingleLineTextArea
public boolean isSingleLineTextArea()Indicates whether this is a single line text area, in which case "growing" won't work as expected.
Returns
true if this is a single line text area
-
setSingleLineTextArea
public void setSingleLineTextArea(boolean singleLineTextArea) Indicates whether this is a single line text area, in which case "growing" won't work as expected.
Parameters
singleLineTextArea: set to true to force a single line text
-
getAlignment
public int getAlignment()Returns the alignment of the TextArea
Returns
the alignment of the TextArea one of: CENTER, LEFT, RIGHT
Deprecated
use Style.getAlignment instead
See also
-
#CENTER
-
#LEFT
-
#RIGHT
-
-
setAlignment
public void setAlignment(int align) Sets the Alignment of the TextArea to one of: CENTER, LEFT, RIGHT
Parameters
align: alignment value
Deprecated
use Style.setAlignment instead
See also
-
#CENTER
-
#LEFT
-
#RIGHT
-
getAbsoluteAlignment
public int getAbsoluteAlignment()Returns the absolute alignment of the TextArea In RTL LEFT alignment is actually RIGHT, but this method returns the actual alignment
Returns
the alignment of the TextArea one of: CENTER, LEFT, RIGHT
Deprecated
this method is redundant and no longer used
See also
-
#CENTER
-
#LEFT
-
#RIGHT
-
-
isPendingCommit
public boolean isPendingCommit()Returns true if the text field is waiting for a commit on editing
Returns
true if a commit is pending
-
getCursorPosition
public int getCursorPosition()Returns the position of the cursor char position
Returns
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
-
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
-
getInputMode
Returns the currently selected input mode
Returns
- Returns:
- the display name of the input mode by default the following modes are supported: Abc, ABC, abc, 123
-
getInputModeOrder
Returns the order in which input modes are toggled
Returns
the order of the input modes
-
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
-
isEnterKey
protected boolean isEnterKey(int keyCode) Indicates the enter key to be used for editing the text area and by the text field
Parameters
keyCode: the key tested
-
getHint
Returns the hint text
Returns
the hint text or null
-
setHint
Sets the TextArea hint text, the hint text is displayed on the TextArea When there is no text in the TextArea
Parameters
hint: the hint text to display
-
getHintIcon
Returns the hint icon
Returns
the hint icon
-
setHintIcon
Sets the TextArea hint icon, the hint is displayed on the TextArea When there is no text in the TextArea
Parameters
icon: the icon
-
setHint
-
getHintLabel
Returns the hint label component that can be customized directly
Returns
hint label component
-
getVerticalAlignment
public int getVerticalAlignment()Returns the vertical alignment of the text field, this only applies to single line text field
NOTE: If the text area is an editable, multi-line text field, and the platform doesn't support vertical alignment with its native text editor, then this will always return
Component#TOP. Currently no platforms support vertical alignment of multiline text areas.Returns
the vertical alignment of the TextField one of: CENTER, TOP, BOTTOM
See also
-
#CENTER
-
#TOP
-
#BOTTOM
-
-
setVerticalAlignment
public void setVerticalAlignment(int valign) Sets the vertical alignment of the text field to one of: CENTER, TOP, BOTTOM
only applies to single line text field
NOTE: If the text area is an editable, multi-line text field, and the platform doesn't support vertical alignment with its native text editor, then
#getVerticalAlignment()will always returnComponent#TOP, no matter what value you set here. Currently no platforms support vertical alignment of multiline text areas.Parameters
valign: alignment value
See also
-
#CENTER
-
#TOP
-
#BOTTOM
-
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
Returns
a string array of property names or null
Deprecated
this mapped to an older iteration of properties that is no longer used
- Overrides:
getBindablePropertyNamesin classComponent
-
getBindablePropertyTypes
Returns the types of the properties that are bindable within this component
Returns
the class for binding
Deprecated
this mapped to an older iteration of properties that is no longer used
- Overrides:
getBindablePropertyTypesin classComponent
-
bindProperty
Binds the given property name to the given bind target
Parameters
-
prop: the property name -
target: the target binder
Deprecated
this mapped to an older iteration of properties that is no longer used
Deprecated
uses the deprecated BindTarget interface
- Overrides:
bindPropertyin classComponent
-
-
unbindProperty
Removes a bind target from the given property name
Parameters
-
prop: the property names -
target: the target binder
Deprecated
this mapped to an older iteration of properties that is no longer used
Deprecated
uses the deprecated BindTarget interface
- Overrides:
unbindPropertyin classComponent
-
-
getBoundPropertyValue
Allows the binding code to extract the value of the property
Parameters
prop: the property
Returns
the value for the property
Deprecated
this mapped to an older iteration of properties that is no longer used
- Overrides:
getBoundPropertyValuein classComponent
-
setBoundPropertyValue
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!
Parameters
-
prop: the property whose value should be set -
value: the value
Deprecated
this mapped to an older iteration of properties that is no longer used
- Overrides:
setBoundPropertyValuein classComponent
-
-
getGrowLimit
public int getGrowLimit()Indicates the maximum number of rows in a text area after it has grown, -1 indicates no limit
Returns
the growLimit
-
setGrowLimit
public void setGrowLimit(int growLimit) Indicates the maximum number of rows in a text area after it has grown, -1 indicates no limit
Parameters
growLimit: the growLimit to set
-
isEndsWith3Points
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. This flag is only applicable when there is a grow limit on the TextArea. E.g. a TextArea with potentially 10 rows can be displayed in 4 rows where the last row can be truncated and end with 3 points. By default this is set to false
Returns
true if this TextArea adds "..." when the text is too long
-
setEndsWith3Points
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. This flag is only applicable when there is a grow limit on the TextArea. E.g. a TextArea with potentially 10 rows can be displayed in 4 rows where the last row can be truncated and end with 3 points. By default this is set to false
Parameters
endsWith3Points: true if text should add "..." at the end
-
registerAsInputDevice
public void registerAsInputDevice()Registers this TextArea as the current input device for the current form.
Deprecated
-
startEditing
public void startEditing()Launches the text field editing, notice that calling this in a callSerially is generally considered good practice -
startEditingAsync
public void startEditingAsync()Launches the text field editing in a callserially call- Specified by:
startEditingAsyncin interfaceEditable- Overrides:
startEditingAsyncin classComponent
-
isEditing
-
stopEditing
public void stopEditing()Stops text editing of this field if it is being edited -
stopEditing
Stops text editing of this field if it is being edited
Parameters
onFinish: invoked when editing stopped
- Specified by:
stopEditingin interfaceEditable- Overrides:
stopEditingin classComponent
-
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.
Returns
the component Style object
We override get style here to return the selected style when editing
Returns
the selected style if editing,
super.getStyle()otherwise -
addDataChangedListener
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
Parameters
d: the listener
-
removeDataChangedListener
Removes the listener for data change events
Parameters
d: the listener
-
addDataChangeListener
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
Parameters
d: the listener
Deprecated
use #addDataChangedListener(DataChangedListener) instead
-
removeDataChangeListener
Removes the listener for data change events
Parameters
d: the listener
Deprecated
use #removeDataChangedListener(DataChangedListener) instead
-
fireDataChanged
public void fireDataChanged(int type, int index) Alert the TextField listeners the text has been changed on the TextField
Parameters
-
type: the event type: Added, Removed or Change -
index: cursor location of the event
-
-
getDoneListener
Gets the done listener of this TextField.
Returns
the done listener or null if not exists
-
setDoneListener
Sets a Done listener on the TextField - notice this listener will be called only on supported platforms that supports done action on the keyboard
Parameters
l: the listener
-
fireDoneEvent
public void fireDoneEvent()Fire the done event to done listener -
fireDoneEvent
public void fireDoneEvent(int keyEvent) -
isActAsLabel
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
Returns
the actAsLabel
-
setActAsLabel
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
Parameters
actAsLabel: the actAsLabel to set
-
shouldRenderComponentSelection
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.
Returns
Defaults to false
Returns
true if editing
- Overrides:
shouldRenderComponentSelectionin classComponent
-
calculateTextSelectionSpan
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: The TextSelection
Since
7.0
-
isTextSelectionEnabled
public boolean isTextSelectionEnabled()Returns true if text selection is enabled on this label. Default is false. To enable text selection, you must enable text selection on the Form with
Form#getTextSelection()andTextSelection#setEnabled(boolean), and also ensure that the label's text selection is enabled via#setTextSelectionEnabled(boolean).Since
7.0
See also
- #setTextSelectionEnabled(boolean)
-
setTextSelectionEnabled
public void setTextSelectionEnabled(boolean enabled) Enables text selection on this TextArea. Text selection must also be enabled on the Form in order to text selection to be activated.
Parameters
enabled
Since
7.0
See also
-
#setTextSelectionEnabled(boolean)
-
Form#getTextSelection()
-
TextSelection#setEnabled(boolean)
-
getTextSelectionSupport
Returns text selection support object for this component. Only used by components that support text selection (e.g. Labels, un-editable text fields, etc..).
Returns
text selection support object
Since
7.0
- Overrides:
getTextSelectionSupportin classComponent
-