public class EditField
- Object
- Component
- EditorView
- EditField
ImplementsActionSource, Animation, Editable, EditorHost, 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);
Constructors
public EditField() | Creates an empty single-line field. |
public EditField(int columns) | Creates an empty single-line field with the given visible column count. |
public EditField(String text) | Creates a single-line field with the given initial text. |
public EditField(String text, int columns) | Creates a single-line field with the given text and visible column count. |
public EditField(String text, String hint) | Creates a single-line field with the given text and hint. |
public EditField(String text, String hint, int constraint) | Creates a single-line field with the given text, hint and constraint. |
public EditField(String text, String hint, int columns, int constraint) | Creates a single-line field with the given text, hint, visible column count and constraint. |
public EditField(int rows, int columns) | Creates an empty multi-line field with the given visible row and column counts (the TextArea equivalent). |
public EditField(String text, int rows, int columns) | Creates a multi-line field with the given text, visible row and column counts (the TextArea equivalent). |
public EditField(String text, int rows, int columns, int constraint) | Creates a multi-line field with the given text, visible row and column counts and constraint (the TextArea equivalent). |
Methods
public boolean isTextInputSupported() | True when the platform can bind a low level text input client (see com.codename1.impl.CodenameOneImplementation#isTextInputSupported). |
public Object startTextInput(TextInputClient client, TextInputConfig config) | Binds the client to the platform text input source and returns an opaque handle. |
public void updateTextInputState(Object handle, TextInputState state) | Pushes the client’s editing state down to the bound input source. |
public void stopTextInput(Object handle) | Unbinds a previously bound text input client. |
public void editorChanged() | Notifies the owning editor that the document content changed so it can fire its change listeners. |
public void fireEditorEvent(String type, String value) | Delivers a semantic editor event (e.g. a code completion request) back to the owning editor. |
public TextInputConfig getConfig() | Returns the configuration describing the desired keyboard type and input behavior. |
public void onEditorAction(int action) | Delivers the keyboard return key action (done / next / search / send) configured through TextInputConfig. |
protected boolean handleTypedText(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). |
public EditField setHint(String hint) | Sets the placeholder text shown while the field is empty. |
public String getHint() | Returns the placeholder text. |
public boolean isSingleLineTextArea() | True for a single-line field (the default). |
public void setSingleLineTextArea(boolean singleLine) | Sets whether this is a single-line field. |
public void setConstraint(int constraint) | Sets the input constraint (one of the TextArea constraint constants) that hints the platform keyboard (e.g. email, numeric, URL). |
public int getConstraint() | Returns the input constraint. |
public void setActionType(int actionType) | Sets the soft-keyboard action button for a single-line field (one of the TextInputConfig#ACTION_DONE family). |
public void setRows(int rows) | Sets the number of visible rows used to compute the preferred height (multi-line fields). |
public int getRows() | Returns the number of visible rows. |
public void setColumns(int columns) | Sets the number of visible columns used to compute the preferred width. |
public int getColumns() | Returns the number of visible columns. |
public void setEditable(boolean editable) | Sets whether the field is editable. |
public boolean isEditable() | Returns whether the field is editable. |
public void addDataChangedListener(DataChangedListener l) | Adds a listener notified whenever the text changes. |
public void removeDataChangedListener(DataChangedListener l) | Removes a data changed listener. |
public void addActionListener(ActionListener l) | Adds a listener notified when the action key (return on a single-line field) is pressed. |
public void removeActionListener(ActionListener l) | Removes an action listener. |
public void paint(Graphics g) | This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering. |
protected Dimension calcPreferredSize() | Calculates the preferred size based on component content. |
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 EditorView
scrollByPixels, setEditorHost, getDocument, getUndoManager, getCaretOffset, setBackgroundColor, setTextColor, setSelectionColor, getTextColor, setText, getText, setEditableState, isEditableState, blur, baseFontSizePixels, setFontSizeDips, getEditorFont, getLineHeight, lineHeightAt, uniformLineHeight, invalidateLayout, lineTopContent, contentTotalHeight, lineAtContentY, getContentLeftInset, contentWidth, hasSelection, getSelectionStart, getSelectionEnd, longPointerPress, paintContent, paintComposingUnderline, paintBeforeContent, paintLineDecorations, lineTop, firstVisibleLine, getHorizontalScroll, getVerticalScroll, getMaximumVerticalScroll, paintLine, offsetAtPoint, consumesRawTextInput, isEditAllowed, replaceRange, documentEdited, documentReplaced, documentReset, captureDocumentState, restoreDocumentState, refreshUndoAfterState, insertText, handleTab, host, deleteBackward, moveCaret, selectAll, copySelection, cutSelection, pasteClipboard, pasteClipboardData, lineContentOffsetX, measureColumnX, columnAtX, lineVisualSegments, laidOut, focusGained, focusLost, deinitialize, animate, pointerPressed, pointerDragged, pointerReleased, keyPressed, keyRepeated, keyReleased, commitText, setComposingText, finishComposing, deleteSurroundingText, onKeyCommand, performUndo, performRedo, getEditingState, getCaretRect, rectForOffset, getTextLength, getTextRange, selectionRects, replaceRange, setSelectionRange, inputFocusGained, inputFocusLost
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, 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, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, 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, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, 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, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, initComponent, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, 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
EditField
public EditField()EditField
public EditField(int columns)Parameters
columnsint- the number of visible columns used to compute the preferred width
EditField
public EditField(String text)Parameters
textString- the initial text
EditField
public EditField(String text, int columns)Parameters
textString- the initial text
columnsint- the number of visible columns
EditField
public EditField(String text, String hint)Parameters
textString- the initial text
hintString- the placeholder shown while empty
EditField
public EditField(String text, String hint, int constraint)Parameters
textString- the initial text
hintString- the placeholder shown while empty
constraintint- one of the
TextAreaconstraint constants (e.g.TextArea#EMAILADDR)
EditField
public EditField(String text, String hint, int columns, int constraint)Parameters
textString- the initial text
hintString- the placeholder shown while empty
columnsint- the number of visible columns
constraintint- one of the
TextAreaconstraint constants (e.g.TextArea#EMAILADDR)
EditField
public EditField(int rows, int columns)TextArea
equivalent). Using this constructor sets the field to multi-line mode.Parameters
rowsint- the number of visible rows used to compute the preferred height
columnsint- the number of visible columns
EditField
public EditField(String text, int rows, int columns)TextArea
equivalent). Using this constructor sets the field to multi-line mode.Parameters
textString- the initial text
rowsint- the number of visible rows
columnsint- the number of visible columns
EditField
public EditField(String text, int rows, int columns, int constraint)TextArea equivalent). Using this constructor sets the field to multi-line mode.Parameters
textString- the initial text
rowsint- the number of visible rows
columnsint- the number of visible columns
constraintint- one of the
TextAreaconstraint constants
Method details
isTextInputSupported
public boolean isTextInputSupported()com.codename1.impl.CodenameOneImplementation#isTextInputSupported).startTextInput
public Object startTextInput(TextInputClient client, TextInputConfig config)updateTextInputState
public void updateTextInputState(Object handle, TextInputState state)stopTextInput
public void stopTextInput(Object handle)editorChanged
public void editorChanged()fireEditorEvent
public void fireEditorEvent(String type, String value)getConfig
public TextInputConfig getConfig()onEditorAction
public void onEditorAction(int action)TextInputConfig.Parameters
actionint- one of the
TextInputConfigACTION_*constants
handleTypedText
protected boolean handleTypedText(String text)Parameters
textString- the text being typed / committed
setHint
public EditField setHint(String hint)Parameters
hintString- the placeholder, or null / empty for none
getHint
public String getHint()isSingleLineTextArea
public boolean isSingleLineTextArea()setSingleLineTextArea
public void setSingleLineTextArea(boolean singleLine)Parameters
singleLineboolean- true for a single line, false for multi-line
setConstraint
public void setConstraint(int constraint)TextArea constraint constants) that hints the platform
keyboard (e.g. email, numeric, URL).Parameters
constraintint- a
TextAreaconstraint constant
getConstraint
public int getConstraint()setActionType
public void setActionType(int actionType)TextInputConfig#ACTION_DONE family).setRows
public void setRows(int rows)getRows
public int getRows()setColumns
public void setColumns(int columns)getColumns
public int getColumns()setEditable
public void setEditable(boolean editable)Parameters
editableboolean- true to allow editing
isEditable
public boolean isEditable()addDataChangedListener
public void addDataChangedListener(DataChangedListener l)removeDataChangedListener
public void removeDataChangedListener(DataChangedListener l)addActionListener
public void addActionListener(ActionListener l)removeActionListener
public void removeActionListener(ActionListener l)paint
public void paint(Graphics g)Parameters
gGraphics- the component graphics
calcPreferredSize
protected Dimension calcPreferredSize()