Class JTextComponent

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
Direct Known Subclasses:
JEditorPane, JTextArea, JTextField

public abstract class JTextComponent extends JComponent implements Scrollable, Accessible
Emulator for JTextComponent.
See Also:
  • Field Details

    • FOCUS_ACCELERATOR_KEY

      public static final String 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

      public static final String 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

      protected Document createDefaultDocument()
      Factory for the default Document. Real Swing subclasses override to pick richer Document models (the EditorKit-driven path in JEditorPane, etc.). Our base picks PlainDocument — 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

      public boolean print(MessageFormat arg0, MessageFormat arg1) throws PrinterException
      Throws:
      PrinterException
    • print

      public boolean print() throws PrinterException
      Throws:
      PrinterException
    • write

      public void write(Writer arg0) throws IOException
      Throws:
      IOException
    • paramString

      protected String paramString()
      Overrides:
      paramString in class JComponent
    • read

      public void read(Reader arg0, Object arg1) throws IOException
      Throws:
      IOException
    • getText

      public String getText()
    • getText

      public String getText(int offs, int len) throws BadLocationException
      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:
      updateUI in class JComponent
    • setUI

      public void setUI(TextUI arg0)
    • getUI

      public TextUI getUI()
      Overrides:
      getUI in class JComponent
    • getDocument

      public Document getDocument()
    • setComponentOrientation

      public void setComponentOrientation(ComponentOrientation o)
      Overrides:
      setComponentOrientation in class Component
    • getActions

      public Action[] getActions()
    • viewToModel

      public int viewToModel(Point arg0)
    • addKeymap

      public static Keymap addKeymap(String arg0, Keymap arg1)
    • 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 — see saveComposedText(int).
    • modelToView

      public Rectangle modelToView(int arg0) throws BadLocationException
      Throws:
      BadLocationException
    • modelToView2D

      public Rectangle2D modelToView2D(int arg0) throws BadLocationException
      Throws:
      BadLocationException
    • viewToModel2D

      public int viewToModel2D(Point2D arg0)
    • isEditable

      public boolean isEditable()
    • cut

      public void cut()
    • paste

      public void paste()
    • setDocument

      public void setDocument(Document doc)
    • removeNotify

      public void removeNotify()
      Overrides:
      removeNotify in class JComponent
    • 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 - if position is outside the Document
    • moveCaretPosition

      public void moveCaretPosition(int pos)
      Throws:
      IllegalArgumentException - if pos is outside the Document
    • getToolTipText

      public String getToolTipText(MouseEvent arg0)
      Overrides:
      getToolTipText in class JComponent
    • getPrintable

      public Printable getPrintable(MessageFormat arg0, MessageFormat arg1)
    • replaceSelection

      public void replaceSelection(String content)
      Replaces the selection with content through 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

      public Keymap getKeymap()
    • getKeymap

      public static Keymap getKeymap(String arg0)
    • getCaret

      public Caret getCaret()
    • setCaret

      public void setCaret(Caret c)
      Installs c as the caret every caret and selection method goes through, and fires "caret". A DefaultCaret is installed fully: it follows the Document from here on and the peer renders it. Any other Caret is used but not installed — WARN — since Caret.install(JTextComponent) takes the JDK's JTextComponent, which this class is not; one that does its setup there starts uninitialised.
    • addCaretListener

      public void addCaretListener(CaretListener listener)
    • removeCaretListener

      public void removeCaretListener(CaretListener listener)
    • getCaretListeners

      public CaretListener[] getCaretListeners()
    • fireCaretUpdate

      protected void fireCaretUpdate(CaretEvent e)
      Notifies the caret listeners, last registered first, as the JDK does.
    • setMargin

      public void setMargin(Insets arg0)
      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 an Insets would 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

      public Insets getMargin()
    • setNavigationFilter

      public void setNavigationFilter(NavigationFilter filter)
      Stores the filter and fires nothing, which is the JDK's whole body. The DefaultCaret hands it every setDot / moveDot, the browser's caret moves included.
    • getNavigationFilter

      public NavigationFilter getNavigationFilter()
    • getHighlighter

      public Highlighter getHighlighter()
    • setHighlighter

      public void setHighlighter(Highlighter arg0)
      Stores the highlighter and fires "highlighter"; nothing is painted. Highlight rendering is user-authored Graphics painting (R_match_swing_errors sub-bucket (b)) — a Highlighter.HighlightPainter draws directly onto a Graphics, which has no counterpart in the DOM. As with setCaret(Caret), the JDK's install / deinstall pair takes the JDK's own JTextComponent and so cannot be called from here. State and notification are owed regardless (R_decline_effect_only, D_owed_events).
    • setKeymap

      public void setKeymap(Keymap arg0)
      Stores the keymap and fires "keymap"; the keymap itself dispatches nothing. Real key dispatch is permanently out of scope per FocusManager / 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 trailing updateInputMap(old, map), which republishes the keymap's bindings into the component's InputMap, is not reproduced: SB-Emulators' InputMap is driven from JComponent.registerKeyboardAction(ActionListener, KeyStroke, int) instead.
    • getDragEnabled

      public boolean getDragEnabled()
    • setDropMode

      public final void setDropMode(DropMode arg0)
      Stores the mode, accepting the two a text component accepts and rejecting the other six with Swing's own exception type — USE_SELECTION and INSERT only, measured on JDK 25 (the ON / ROWS / COLS modes belong to list, table and tree).
    • getDropMode

      public final DropMode getDropMode()
    • removeKeymap

      public static Keymap removeKeymap(String arg0)
    • getCaretColor

      public Color getCaretColor()
    • setCaretColor

      public void setCaretColor(Color arg0)
      The one colour of the four with a real effect: caret-color is 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 sets caret-color on that inner element directly would still win — the declaration is pushed, not enforced. Null removes it, letting inheritance resume.
    • getSelectionColor

      public Color getSelectionColor()
    • setSelectionColor

      public void setSelectionColor(Color arg0)
      Stores and fires; no paint. Selection colours live behind the ::selection pseudo-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 as setSelectedTextColor(Color) and setDisabledTextColor(Color). State and notification are owed regardless (R_decline_effect_only, D_owed_events).
    • getSelectedTextColor

      public Color getSelectedTextColor()
    • setSelectedTextColor

      public void setSelectedTextColor(Color arg0)
      Stores and fires; no paint — see setSelectionColor(Color).
    • getDisabledTextColor

      public Color getDisabledTextColor()
    • setDisabledTextColor

      public void setDisabledTextColor(Color arg0)
      Stores and fires; no paint. Needs a :disabled rule inside the peer's shadow root — see setSelectionColor(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 Shortcuts registration — 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

      public void setText(String t)
      Replaces the Document's text in one replace, so a DocumentFilter sees a replace; a Document that is not an AbstractDocument gets a remove and an insert.
    • getSelectedText

      public String getSelectedText()
      Returns:
      the selected text, or null when nothing is selected
      Throws:
      IllegalArgumentException - when the selection runs past the Document, which getCaret().moveDot can leave it doing
    • setSelectionStart

      public void setSelectionStart(int selectionStart)
      Routes through select(int, int), as the JDK does, so both ends clamp alike.
    • setSelectionEnd

      public void setSelectionEnd(int selectionEnd)
      Routes through select(int, int), as the JDK does, so both ends clamp alike.
    • selectAll

      public void selectAll()
    • getPreferredScrollableViewportSize

      public Dimension getPreferredScrollableViewportSize()
      Specified by:
      getPreferredScrollableViewportSize in interface Scrollable
    • getScrollableUnitIncrement

      public int getScrollableUnitIncrement(Rectangle arg0, int arg1, int arg2)
      Specified by:
      getScrollableUnitIncrement in interface Scrollable
    • getScrollableBlockIncrement

      public int getScrollableBlockIncrement(Rectangle arg0, int arg1, int arg2)
      Specified by:
      getScrollableBlockIncrement in interface Scrollable
    • getScrollableTracksViewportWidth

      public boolean getScrollableTracksViewportWidth()
      Specified by:
      getScrollableTracksViewportWidth in interface Scrollable
    • getScrollableTracksViewportHeight

      public boolean getScrollableTracksViewportHeight()
      Specified by:
      getScrollableTracksViewportHeight in interface Scrollable
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()
      Specified by:
      getAccessibleContext in interface Accessible
      Overrides:
      getAccessibleContext in class Component
    • getInputMethodRequests

      public InputMethodRequests getInputMethodRequests()
      Overrides:
      getInputMethodRequests in class Component