Class EditField
- All Implemented Interfaces:
Animation, Editable, EditorHost, ActionSource, StyleListener, TextHolder, TextInputClient
A pure Codename One text field.
EditField is a drop-in alternative to TextField / TextArea that edits text entirely with the
framework's own text engine (the same engine that backs CodeEditor and RichTextArea) instead of
a native peer. Selection, caret movement, word / line navigation, undo and clipboard all work on
every port: on iOS, Android and JavaScript the platform soft keyboard, hardware keyboard and IME
drive it through the low-level text-input SPI; on the desktop ports the raw physical-keyboard path
is used. Because there is no native peer the field is a real, self-contained lightweight component
-- it never floats above the UI, scrolls perfectly with its parent and can live anywhere a
Component can.
It intentionally mirrors the common TextField / TextArea API (#setText(String), #getText(),
#setHint(String), #setConstraint(int), #addDataChangedListener(DataChangedListener),
#addActionListener(ActionListener), #setSingleLineTextArea(boolean)) and implements the same
TextHolder and ActionSource interfaces those components do, so code written against those
interfaces (validators, form binding, generic listeners) works unchanged. It also offers the same
constructor families: the TextField-style constructors create single-line fields while the
TextArea-style (rows, columns) constructors create multi-line editors, making the single- vs
multi-line choice explicit at construction. It is still a distinct class -- not assignable to
TextField / TextArea -- so switching to the pure engine is always a deliberate, opt-in choice.
// single line, like TextField
EditField name = new EditField("", "Name", TextArea.EMAILADDR);
name.addActionListener(e -> submit(name.getText()));
form.add(name);
// multi line, like TextArea
EditField notes = new EditField(5, 30);
form.add(notes);
-
Field Summary
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_CURSORFields inherited from interface TextInputClient
KEY_BACKSPACE, KEY_COPY, KEY_CUT, KEY_DELETE, KEY_DOWN, KEY_END, KEY_ESCAPE, KEY_HOME, KEY_LEFT, KEY_PAGE_DOWN, KEY_PAGE_UP, KEY_PASTE, KEY_REDO, KEY_RIGHT, KEY_SELECT_ALL, KEY_TAB, KEY_UNDO, KEY_UP, MOD_ALT, MOD_CTRL, MOD_SHIFT -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty single-line field.EditField(int columns) Creates an empty single-line field with the given visible column count.EditField(int rows, int columns) Creates an empty multi-line field with the given visible row and column counts (theTextAreaequivalent).Creates a single-line field with the given initial text.Creates a single-line field with the given text and visible column count.Creates a multi-line field with the given text, visible row and column counts (theTextAreaequivalent).Creates a multi-line field with the given text, visible row and column counts and constraint (theTextAreaequivalent).Creates a single-line field with the given text and hint.Creates a single-line field with the given text, hint and constraint.Creates a single-line field with the given text, hint, visible column count and constraint. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener notified when the action key (return on a single-line field) is pressed.voidAdds a listener notified whenever the text changes.protected DimensionCalculates the preferred size based on component content.voidNotifies the owning editor that the document content changed so it can fire its change listeners.voidfireEditorEvent(String type, String value) Delivers a semantic editor event (e.g. a code completion request) back to the owning editor.intReturns the number of visible columns.Returns the configuration describing the desired keyboard type and input behavior.intReturns the input constraint.getHint()Returns the placeholder text.intgetRows()Returns the number of visible rows.protected booleanhandleTypedText(String text) Hook giving feature layers a chance to intercept typed text before the default insertion (used by the code editor for bracket / quote auto close, tab expansion and auto indent).booleanReturns whether the field is editable.booleanTrue for a single-line field (the default).booleanTrue when the platform can bind a low level text input client (seecom.codename1.impl.CodenameOneImplementation#isTextInputSupported).voidonEditorAction(int action) Delivers the keyboard return key action (done / next / search / send) configured throughTextInputConfig.voidThis 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.voidRemoves an action listener.voidRemoves a data changed listener.voidsetActionType(int actionType) Sets the soft-keyboard action button for a single-line field (one of theTextInputConfig#ACTION_DONEfamily).voidsetColumns(int columns) Sets the number of visible columns used to compute the preferred width.voidsetConstraint(int constraint) Sets the input constraint (one of theTextAreaconstraint constants) that hints the platform keyboard (e.g. email, numeric, URL).voidsetEditable(boolean editable) Sets whether the field is editable.Sets the placeholder text shown while the field is empty.voidsetRows(int rows) Sets the number of visible rows used to compute the preferred height (multi-line fields).voidsetSingleLineTextArea(boolean singleLine) Sets whether this is a single-line field.startTextInput(TextInputClient client, TextInputConfig config) Binds the client to the platform text input source and returns an opaque handle.voidstopTextInput(Object handle) Unbinds a previously bound text input client.voidupdateTextInputState(Object handle, TextInputState state) Pushes the client's editing state down to the bound input source.Methods inherited from class EditorView
animate, baseFontSizePixels, blur, captureDocumentState, columnAtX, commitText, contentTotalHeight, contentWidth, copySelection, deinitialize, deleteSurroundingText, documentEdited, documentReplaced, documentReset, finishComposing, firstVisibleLine, focusGained, focusLost, getCaretOffset, getCaretRect, getContentLeftInset, getDocument, getEditingState, getEditorFont, getHorizontalScroll, getLineHeight, getMaximumVerticalScroll, getSelectionEnd, getSelectionStart, getText, getTextColor, getTextLength, getTextRange, getUndoManager, getVerticalScroll, handleTab, hasSelection, host, inputFocusGained, inputFocusLost, insertText, invalidateLayout, isEditableState, keyPressed, keyReleased, keyRepeated, laidOut, lineAtContentY, lineContentOffsetX, lineHeightAt, lineTop, lineTopContent, lineVisualSegments, longPointerPress, measureColumnX, moveCaret, offsetAtPoint, onKeyCommand, paintBeforeContent, paintComposingUnderline, paintContent, paintLine, paintLineDecorations, pasteClipboardData, performRedo, performUndo, pointerDragged, pointerPressed, pointerReleased, rectForOffset, refreshUndoAfterState, replaceRange, replaceRange, restoreDocumentState, scrollByPixels, selectAll, selectionRects, setBackgroundColor, setComposingText, setEditableState, setEditorHost, setFontSizeDips, setSelectionColor, setSelectionRange, setText, setTextColor, uniformLineHeightMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, cancelRepaints, clearClientProperties, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, getAbsoluteX, getAbsoluteY, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, 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, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getSideGap, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initLaf, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, longKeyPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, 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, setPullToRefresh, 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, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface TextHolder
getText, setText
-
Constructor Details
-
EditField
public EditField()Creates an empty single-line field. -
EditField
public EditField(int columns) Creates an empty single-line field with the given visible column count.
Parameters
columns: the number of visible columns used to compute the preferred width
-
EditField
Creates a single-line field with the given initial text.
Parameters
text: the initial text
-
EditField
Creates a single-line field with the given text and visible column count.
Parameters
-
text: the initial text -
columns: the number of visible columns
-
-
EditField
-
EditField
-
EditField
Creates a single-line field with the given text, hint, visible column count and constraint.
Parameters
-
text: the initial text -
hint: the placeholder shown while empty -
columns: the number of visible columns -
constraint: one of theTextAreaconstraint constants (e.g.TextArea#EMAILADDR)
-
-
EditField
public EditField(int rows, int columns) Creates an empty multi-line field with the given visible row and column counts (the
TextAreaequivalent). Using this constructor sets the field to multi-line mode.Parameters
-
rows: the number of visible rows used to compute the preferred height -
columns: the number of visible columns
-
-
EditField
Creates a multi-line field with the given text, visible row and column counts (the
TextAreaequivalent). Using this constructor sets the field to multi-line mode.Parameters
-
text: the initial text -
rows: the number of visible rows -
columns: the number of visible columns
-
-
EditField
Creates a multi-line field with the given text, visible row and column counts and constraint (the
TextAreaequivalent). Using this constructor sets the field to multi-line mode.Parameters
-
text: the initial text -
rows: the number of visible rows -
columns: the number of visible columns -
constraint: one of theTextAreaconstraint constants
-
-
-
Method Details
-
isTextInputSupported
public boolean isTextInputSupported()Description copied from interface:EditorHostTrue when the platform can bind a low level text input client (seecom.codename1.impl.CodenameOneImplementation#isTextInputSupported).- Specified by:
isTextInputSupportedin interfaceEditorHost
-
startTextInput
Description copied from interface:EditorHostBinds the client to the platform text input source and returns an opaque handle.- Specified by:
startTextInputin interfaceEditorHost
-
updateTextInputState
Description copied from interface:EditorHostPushes the client's editing state down to the bound input source.- Specified by:
updateTextInputStatein interfaceEditorHost
-
stopTextInput
Description copied from interface:EditorHostUnbinds a previously bound text input client.- Specified by:
stopTextInputin interfaceEditorHost
-
editorChanged
public void editorChanged()Description copied from interface:EditorHostNotifies the owning editor that the document content changed so it can fire its change listeners.- Specified by:
editorChangedin interfaceEditorHost
-
fireEditorEvent
Description copied from interface:EditorHostDelivers a semantic editor event (e.g. a code completion request) back to the owning editor.- Specified by:
fireEditorEventin interfaceEditorHost
-
getConfig
Description copied from interface:TextInputClientReturns the configuration describing the desired keyboard type and input behavior.- Specified by:
getConfigin interfaceTextInputClient- Overrides:
getConfigin classEditorView
-
onEditorAction
public void onEditorAction(int action) Description copied from interface:TextInputClientDelivers the keyboard return key action (done / next / search / send) configured through
TextInputConfig.Parameters
action: one of theTextInputConfigACTION_*constants
- Specified by:
onEditorActionin interfaceTextInputClient- Overrides:
onEditorActionin classEditorView
-
handleTypedText
Description copied from class:EditorViewHook giving feature layers a chance to intercept typed text before the default insertion (used by the code editor for bracket / quote auto close, tab expansion and auto indent). Return true when the text was consumed. The default returns false.
Parameters
text: the text being typed / committed
- Overrides:
handleTypedTextin classEditorView
-
setHint
-
getHint
Returns the placeholder text. -
isSingleLineTextArea
public boolean isSingleLineTextArea()True for a single-line field (the default). A single-line field fires its action listeners on the return key instead of inserting a line break. -
setSingleLineTextArea
public void setSingleLineTextArea(boolean singleLine) Sets whether this is a single-line field. Passing false makes it a multi-line editor.
Parameters
singleLine: true for a single line, false for multi-line
-
setConstraint
public void setConstraint(int constraint) Sets the input constraint (one of the
TextAreaconstraint constants) that hints the platform keyboard (e.g. email, numeric, URL).Parameters
constraint: aTextAreaconstraint constant
-
getConstraint
public int getConstraint()Returns the input constraint. -
setActionType
public void setActionType(int actionType) Sets the soft-keyboard action button for a single-line field (one of theTextInputConfig#ACTION_DONEfamily). -
setRows
public void setRows(int rows) Sets the number of visible rows used to compute the preferred height (multi-line fields). -
getRows
public int getRows()Returns the number of visible rows. -
setColumns
public void setColumns(int columns) Sets the number of visible columns used to compute the preferred width. -
getColumns
public int getColumns()Returns the number of visible columns. -
setEditable
public void setEditable(boolean editable) Sets whether the field is editable. A non-editable field still allows selection and copying.
Parameters
editable: true to allow editing
-
isEditable
public boolean isEditable()Returns whether the field is editable.- Specified by:
isEditablein interfaceEditable- Overrides:
isEditablein classComponent
-
addDataChangedListener
Adds a listener notified whenever the text changes. -
removeDataChangedListener
Removes a data changed listener. -
addActionListener
Adds a listener notified when the action key (return on a single-line field) is pressed.- Specified by:
addActionListenerin interfaceActionSource
-
removeActionListener
Removes an action listener.- Specified by:
removeActionListenerin interfaceActionSource
-
paint
Description copied from class:ComponentThis 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
- Specified by:
paintin interfaceAnimation- Overrides:
paintin classEditorView
-
calcPreferredSize
Description copied from class:ComponentCalculates 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 classEditorView
-