Class JTextComponent
java.lang.Object
vaadinx.awt.Component
vaadinx.awt.Container
vaadinx.swing.JComponent
vaadinx.swing.text.JTextComponent
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
- Direct Known Subclasses:
JEditorPane, JTextArea, JTextField
Emulator for
JTextComponent.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey the JDK registers its built-in keymap under; kept for API shape.static final StringThe JDK's own name for the"focusAcceleratorKey"bound property.protected booleanFields inherited from class JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, FILL_CHROME, FILL_DEFAULT, LEFT_ALIGNMENT, listenerList, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCaretListener(CaretListener listener) static Keymapvoidcopy()protected DocumentFactory for the defaultDocument.voidcut()protected voidNotifies the caret listeners, last registered first, as the JDK does.Action[]getCaret()intbooleanfinal DropModecharstatic KeymapgetPrintable(MessageFormat arg0, MessageFormat arg1) intgetScrollableBlockIncrement(Rectangle arg0, int arg1, int arg2) booleanbooleanintgetScrollableUnitIncrement(Rectangle arg0, int arg1, int arg2) intintgetText()getText(int offs, int len) getToolTipText(MouseEvent arg0) getUI()booleanmodelToView(int arg0) modelToView2D(int arg0) voidmoveCaretPosition(int pos) protected Stringvoidpaste()booleanprint()booleanprint(MessageFormat arg0, MessageFormat arg1) booleanprint(MessageFormat arg0, MessageFormat arg1, boolean arg2, PrintService arg3, PrintRequestAttributeSet arg4, boolean arg5) voidvoidremoveCaretListener(CaretListener listener) static KeymapremoveKeymap(String arg0) voidvoidreplaceSelection(String content) Replaces the selection withcontentthrough the Document, so a filter sees the edit; with nothing selected, inserts at the caret.protected voidRestores nothing — seesaveComposedText(int).protected booleansaveComposedText(int pos) voidselect(int selectionStart, int selectionEnd) Selects[selectionStart, selectionEnd], clamping both into the Document and collapsing an end before the start onto the start, as the JDK does.voidvoidInstallscas the caret every caret and selection method goes through, and fires"caret".voidsetCaretColor(Color arg0) The one colour of the four with a real effect:caret-coloris an inherited CSS property, so a declaration on the peer's host element reaches the<input>inside Vaadin's shadow root without needing a shadow-part rule.voidsetCaretPosition(int position) voidvoidsetDisabledTextColor(Color arg0) Stores and fires; no paint.voidsetDocument(Document doc) voidsetDragEnabled(boolean arg0) Stores the flag; text-drag-out is the browser's to offer, and R_decline_effect_only lets the effect go but not the state.final voidsetDropMode(DropMode arg0) Stores the mode, accepting the two a text component accepts and rejecting the other six with Swing's own exception type —USE_SELECTIONandINSERTonly, measured on JDK 25 (the ON / ROWS / COLS modes belong to list, table and tree).voidsetEditable(boolean b) voidsetFocusAccelerator(char arg0) Uppercases the key, stores it, and fires two events —FOCUS_ACCELERATOR_KEY(i.e.voidsetHighlighter(Highlighter arg0) Stores the highlighter and fires"highlighter"; nothing is painted.voidStores the keymap and fires"keymap"; the keymap itself dispatches nothing.voidStores the margin and fires"margin"; the pixel inset is not pushed.voidsetNavigationFilter(NavigationFilter filter) Stores the filter and fires nothing, which is the JDK's whole body.voidsetSelectedTextColor(Color arg0) Stores and fires; no paint — seesetSelectionColor(Color).voidsetSelectionColor(Color arg0) Stores and fires; no paint.voidsetSelectionEnd(int selectionEnd) Routes throughselect(int, int), as the JDK does, so both ends clamp alike.voidsetSelectionStart(int selectionStart) Routes throughselect(int, int), as the JDK does, so both ends clamp alike.voidReplaces the Document's text in onereplace, so aDocumentFiltersees a replace; a Document that is not anAbstractDocumentgets a remove and an insert.voidvoidupdateUI()intviewToModel(Point arg0) intviewToModel2D(Point2D arg0) voidMethods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, addSlotChild, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, fireHierarchyEvent, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, peerContentElement, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeSlotChild, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, applyBackgroundToPeer, applyVisibleToPeer, awtListeners, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, defaultFillCssClass, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, fireComponentEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isThemeDefault, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, suppressMouseBridge, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, withPeer, withPeerOnLiveUI
-
Field Details
-
FOCUS_ACCELERATOR_KEY
The JDK's own name for the"focusAcceleratorKey"bound property.setFocusAccelerator(char)fires it and"focusAccelerator"— the JDK fires both, with a source comment naming the compatibility bug (4341002) that made it fire the wrong name first (D_owed_events).- See Also:
-
DEFAULT_KEYMAP
Key the JDK registers its built-in keymap under; kept for API shape.- See Also:
-
preventPeerEvents
protected boolean preventPeerEvents
-
-
Constructor Details
-
JTextComponent
public JTextComponent() -
JTextComponent
protected JTextComponent(com.vaadin.flow.component.Component peer)
-
-
Method Details
-
createDefaultDocument
Factory for the defaultDocument. Real Swing subclasses override to pick richer Document models (the EditorKit-driven path in JEditorPane, etc.). Our base picksPlainDocument— the simplest line- oriented model, and what JTextField would pick anyway. -
copy
public void copy() -
print
public boolean print(MessageFormat arg0, MessageFormat arg1, boolean arg2, PrintService arg3, PrintRequestAttributeSet arg4, boolean arg5) throws PrinterException - Throws:
PrinterException
-
print
- Throws:
PrinterException
-
print
- Throws:
PrinterException
-
write
- Throws:
IOException
-
paramString
- Overrides:
paramStringin classJComponent
-
read
- Throws:
IOException
-
getText
-
getText
- Throws:
BadLocationException
-
setEditable
public void setEditable(boolean b) -
setDragEnabled
public void setDragEnabled(boolean arg0) Stores the flag; text-drag-out is the browser's to offer, and R_decline_effect_only lets the effect go but not the state. -
updateUI
public void updateUI()- Overrides:
updateUIin classJComponent
-
setUI
-
getUI
- Overrides:
getUIin classJComponent
-
getDocument
-
setComponentOrientation
- Overrides:
setComponentOrientationin classComponent
-
getActions
-
viewToModel
-
addKeymap
-
saveComposedText
protected boolean saveComposedText(int pos) - Returns:
- always
false: the browser composes input-method text, so none reaches the Document uncommitted
-
restoreComposedText
protected void restoreComposedText()Restores nothing — seesaveComposedText(int). -
modelToView
- Throws:
BadLocationException
-
modelToView2D
- Throws:
BadLocationException
-
viewToModel2D
-
isEditable
public boolean isEditable() -
cut
public void cut() -
paste
public void paste() -
setDocument
-
removeNotify
public void removeNotify()- Overrides:
removeNotifyin classJComponent
-
getSelectionEnd
public int getSelectionEnd() -
select
public void select(int selectionStart, int selectionEnd) Selects[selectionStart, selectionEnd], clamping both into the Document and collapsing an end before the start onto the start, as the JDK does. -
getSelectionStart
public int getSelectionStart() -
setCaretPosition
public void setCaretPosition(int position) - Throws:
IllegalArgumentException- ifpositionis outside the Document
-
moveCaretPosition
public void moveCaretPosition(int pos) - Throws:
IllegalArgumentException- ifposis outside the Document
-
getToolTipText
- Overrides:
getToolTipTextin classJComponent
-
getPrintable
-
replaceSelection
Replaces the selection withcontentthrough the Document, so a filter sees the edit; with nothing selected, inserts at the caret. The caret then follows the edit under its update policy, as it follows any other. -
getKeymap
-
getKeymap
-
getCaret
-
setCaret
Installscas the caret every caret and selection method goes through, and fires"caret". ADefaultCaretis installed fully: it follows the Document from here on and the peer renders it. Any otherCaretis used but not installed — WARN — sinceCaret.install(JTextComponent)takes the JDK'sJTextComponent, which this class is not; one that does its setup there starts uninitialised. -
addCaretListener
-
removeCaretListener
-
getCaretListeners
-
fireCaretUpdate
Notifies the caret listeners, last registered first, as the JDK does. -
setMargin
Stores the margin and fires"margin"; the pixel inset is not pushed. Vaadin's text controls take their inner padding from theme custom properties on a shadow part, not from an inline style on the host, so honouring anInsetswould need the shadow-root CSS mechanism (SD_add_css_rule) extended to the input family — a separate pass, and R_layouts_close_enough territory either way. State and notification are owed regardless (R_decline_effect_only, D_owed_events). -
getMargin
-
getHighlighter
-
setHighlighter
Stores the highlighter and fires"highlighter"; nothing is painted. Highlight rendering is user-authoredGraphicspainting (R_match_swing_errors sub-bucket (b)) — aHighlighter.HighlightPainterdraws directly onto aGraphics, which has no counterpart in the DOM. As withsetCaret(Caret), the JDK'sinstall/deinstallpair takes the JDK's ownJTextComponentand so cannot be called from here. State and notification are owed regardless (R_decline_effect_only, D_owed_events). -
setKeymap
Stores the keymap and fires"keymap"; the keymap itself dispatches nothing. Real key dispatch is permanently out of scope perFocusManager/ D_focus_managers, so what is declined here is the effect only — the state and the notification are owed (R_decline_effect_only, D_owed_events). The JDK's trailingupdateInputMap(old, map), which republishes the keymap's bindings into the component'sInputMap, is not reproduced: SB-Emulators' InputMap is driven fromJComponent.registerKeyboardAction(ActionListener, KeyStroke, int)instead. -
getDragEnabled
public boolean getDragEnabled() -
setDropMode
Stores the mode, accepting the two a text component accepts and rejecting the other six with Swing's own exception type —USE_SELECTIONandINSERTonly, measured on JDK 25 (the ON / ROWS / COLS modes belong to list, table and tree). -
getDropMode
-
removeKeymap
-
getCaretColor
-
setCaretColor
The one colour of the four with a real effect:caret-coloris an inherited CSS property, so a declaration on the peer's host element reaches the<input>inside Vaadin's shadow root without needing a shadow-part rule. A theme that setscaret-coloron that inner element directly would still win — the declaration is pushed, not enforced. Null removes it, letting inheritance resume. -
getSelectionColor
-
setSelectionColor
Stores and fires; no paint. Selection colours live behind the::selectionpseudo-element, which cannot be expressed as an inline style and so needs the shadow-root CSS mechanism (SD_add_css_rule) extended past the RTE — the same blocker assetSelectedTextColor(Color)andsetDisabledTextColor(Color). State and notification are owed regardless (R_decline_effect_only, D_owed_events). -
getSelectedTextColor
-
setSelectedTextColor
Stores and fires; no paint — seesetSelectionColor(Color). -
getDisabledTextColor
-
setDisabledTextColor
Stores and fires; no paint. Needs a:disabledrule inside the peer's shadow root — seesetSelectionColor(Color). -
setFocusAccelerator
public void setFocusAccelerator(char arg0) Uppercases the key, stores it, and fires two events —FOCUS_ACCELERATOR_KEY(i.e."focusAcceleratorKey") and"focusAccelerator"— because the JDK fires both, deliberately: its own source comments the compatibility bug (4341002) that shipped the wrong name and the added correct one. Both carry the uppercased value, so a listener never sees the argument as passed.The Alt+key focus jump itself is not wired — that would be a Vaadin
Shortcutsregistration — so this declines the effect only: state and notification are owed regardless (R_decline_effect_only, D_owed_events). -
getFocusAccelerator
public char getFocusAccelerator() -
getCaretPosition
public int getCaretPosition()- Returns:
- the caret's dot. A caret the user moved in the browser has reached it by the time the server handles the next event the browser sends, and within a second otherwise
-
setText
Replaces the Document's text in onereplace, so aDocumentFiltersees a replace; a Document that is not anAbstractDocumentgets a remove and an insert. -
getSelectedText
- Returns:
- the selected text, or
nullwhen nothing is selected - Throws:
IllegalArgumentException- when the selection runs past the Document, whichgetCaret().moveDotcan leave it doing
-
setSelectionStart
public void setSelectionStart(int selectionStart) Routes throughselect(int, int), as the JDK does, so both ends clamp alike. -
setSelectionEnd
public void setSelectionEnd(int selectionEnd) Routes throughselect(int, int), as the JDK does, so both ends clamp alike. -
selectAll
public void selectAll() -
getPreferredScrollableViewportSize
- Specified by:
getPreferredScrollableViewportSizein interfaceScrollable
-
getScrollableUnitIncrement
- Specified by:
getScrollableUnitIncrementin interfaceScrollable
-
getScrollableBlockIncrement
- Specified by:
getScrollableBlockIncrementin interfaceScrollable
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()- Specified by:
getScrollableTracksViewportWidthin interfaceScrollable
-
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()- Specified by:
getScrollableTracksViewportHeightin interfaceScrollable
-
getAccessibleContext
- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classComponent
-
getInputMethodRequests
- Overrides:
getInputMethodRequestsin classComponent
-