public abstract class InputComponent
ImplementsAnimation, Editable, Iterable<Component>, StyleListener
Known subtypesPickerComponent, TextComponent
A base class for com.codename1.ui.TextComponent, com.codename1.ui.PickerComponent
and potentially other components that wish to accept input in a dynamic way that matches iOS and
Android native input guidelines.
It is highly recommended to use input components in the context of a
com.codename1.ui.layouts.TextModeLayout. This allows the layout to implicitly adapt to the on-top
mode and use a box layout Y mode for iOS and other platforms.
This class supports several theme constants:
textComponentErrorColora hex RGB color which defaults to null in which case this has no effect. When defined this will change the color of the border and label to the given color to match the material design styling.textComponentErrorLineBorderBoolwhen set tofalse, this will prevent the text component from applying an underline border when there is a validation error. Defaults totrue.textComponentOnTopBooltoggles the on top mode see#onTopMode(boolean)textComponentFieldUIIDsets the UIID of the text field to something other thanTextFieldwhich is useful for platforms such as iOS where the look of the text field is different within the text componentinputComponentErrorMultilineBoolsets the error label to multiline when activated
The following code demonstrates a simple set of inputs and validation as it appears in iOS, Android and with validation errors
TextModeLayout tl = new TextModeLayout(3, 2);
Form f = new Form("Pixel Perfect", tl);
TextComponent title = new TextComponent().label("Title");
TextComponent price = new TextComponent().label("Price");
TextComponent location = new TextComponent().label("Location");
PickerComponent date = PickerComponent.createDate(new Date()).label("Date");
TextComponent description = new TextComponent().label("Description").multiline(true);
Validator val = new Validator();
val.addConstraint(title, new LengthConstraint(2));
val.addConstraint(price, new NumericConstraint(true));
f.add(tl.createConstraint().widthPercentage(60), title);
f.add(tl.createConstraint().widthPercentage(40), date);
f.add(location);
f.add(price);
f.add(tl.createConstraint().horizontalSpan(2), description);
f.setEditOnShow(title.getField());
f.show();
Constructors
protected InputComponent() | Protected constructor for subclasses to override |
Methods
public static void group(Component... cmps) | Groups together multiple text components and labels so they align properly, this is implicitly invoked by com.codename1.ui.layouts.TextModeLayout so this method is unnecessary when using that layout |
public static boolean isMultiLineErrorMessage() | True if error messages should be multiline by default. |
public static void setMultiLineErrorMessage(boolean aMultiLineErrorMessage) | True if error messages should be multiline by default. |
protected final void initInput() | This method must be invoked by the constructor of the subclasses to initialize the UI |
protected TextHolder createErrorLabel() | Can be overriden by subclasses to support custom error label components |
protected Dimension calcPreferredSize() | Calculates the preferred size based on component content. |
public abstract Component getEditor() | Returns the editor component e.g. text field picker etc. |
public InputComponent onTopMode(boolean onTopMode) | Sets the on top mode which places the label above the text when true. |
public boolean isOnTopMode() | Indicates the on top mode which places the label above the text when true. |
public InputComponent errorMessage(String errorMessage) | Sets the text of the error label |
public InputComponent descriptionMessage(String descriptionMessage) | Sets the text of the description label which currently only applies in the onTop mode. |
public InputComponent label(String text) | Sets the text of the label |
public InputComponent actionUIID(String uiid) | Sets the UIID for the action button |
public String getActionUIID() | UIID for the action button |
public InputComponent actionAsButton(boolean asButton) | Indicates the action should behave as a button next to the component and not layered on top of the text component. |
public boolean isActionAsButton() | Indicates the action should behave as a button next to the component and not layered on top of the text component. |
public InputComponent actionText(String text) | Provides the text of the action button |
public String getActionText() | Provides the text of the action button |
public InputComponent action(char icon) | Sets the icon for the action button |
public InputComponent actionClick(ActionListener c) | Binds an event for the action button |
public Button getAction() | Returns the button underlying the action button that is placed on the right of the field on top of it |
public Object getPropertyValue(String name) | Returns the current value of the property name, this method is used by the GUI builder |
public String setPropertyValue(String name, Object value) | Sets a new value to the given property, returns an error message if failed and null if successful. |
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 Container
encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, pointerPressed, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, 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, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, 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, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, deinitialize, initComponent, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, 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, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip
Constructor details
InputComponent
protected InputComponent()Method details
group
public static void group(Component... cmps)com.codename1.ui.layouts.TextModeLayout so this method is unnecessary when using that
layoutParameters
cmpsComponent...- a list of components if it’s a text component that is not in the on top mode the width of the labels will be aligned
isMultiLineErrorMessage
public static boolean isMultiLineErrorMessage()inputComponentErrorMultilineBoolReturns
setMultiLineErrorMessage
public static void setMultiLineErrorMessage(boolean aMultiLineErrorMessage)inputComponentErrorMultilineBoolParameters
aMultiLineErrorMessageboolean- the multiLineErrorMessage to set
initInput
protected final void initInput()createErrorLabel
protected TextHolder createErrorLabel()Returns
ErrorLabel UIIDcalcPreferredSize
protected Dimension calcPreferredSize()Returns
getEditor
public abstract Component getEditor()Returns
onTopMode
public InputComponent onTopMode(boolean onTopMode)textComponentOnTopBool
theme constant which defaults to falseParameters
onTopModeboolean- true for the label to be above the text
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");isOnTopMode
public boolean isOnTopMode()textComponentOnTopBool
theme constant which defaults to falseReturns
errorMessage
public InputComponent errorMessage(String errorMessage)Parameters
errorMessageString- the text
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");descriptionMessage
public InputComponent descriptionMessage(String descriptionMessage)Parameters
descriptionMessageString- the text
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");label
public InputComponent label(String text)Parameters
textString- the text
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");actionUIID
public InputComponent actionUIID(String uiid)Parameters
uiidString- a custom UIID for the action
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");getActionUIID
public String getActionUIID()Returns
actionAsButton
public InputComponent actionAsButton(boolean asButton)Parameters
asButtonboolean- true so the action will act like a button
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");isActionAsButton
public boolean isActionAsButton()Returns
actionText
public InputComponent actionText(String text)Parameters
textString- the text that should appear on the action button
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");getActionText
public String getActionText()Returns
action
public InputComponent action(char icon)Parameters
iconchar- the icon constant from
com.codename1.ui.FontImage
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");actionClick
public InputComponent actionClick(ActionListener c)Parameters
cActionListener- action listener callback
Returns
TextComponent tc = new TextComponent().text("Text").label("Label");getAction
public Button getAction()Returns
getPropertyValue
public Object getPropertyValue(String name)Parameters
nameString- the name of the property
Returns
setPropertyValue
public String setPropertyValue(String name, Object value)Parameters
nameString- the name of the property
valueObject- new value for the property