Class JTable

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableModelListener, Scrollable, FieldReconciler.Reconcilable, TableColumnModelListener

Emulator for JTable, over an SJTable peer; R_leaf_peer_lockdown-locked-down (JDK leaf — private peer ctor). Two-layer column model with bridge listeners; per-class TableCellRenderer registry on the emulator, dynamic Vaadin renderers on the surrogate.
See Also:
  • Field Details

    • AUTO_RESIZE_OFF

      public static final int AUTO_RESIZE_OFF
      See Also:
    • AUTO_RESIZE_NEXT_COLUMN

      public static final int AUTO_RESIZE_NEXT_COLUMN
      See Also:
    • AUTO_RESIZE_SUBSEQUENT_COLUMNS

      public static final int AUTO_RESIZE_SUBSEQUENT_COLUMNS
      See Also:
    • AUTO_RESIZE_LAST_COLUMN

      public static final int AUTO_RESIZE_LAST_COLUMN
      See Also:
    • AUTO_RESIZE_ALL_COLUMNS

      public static final int AUTO_RESIZE_ALL_COLUMNS
      See Also:
    • columnModel

      protected TableColumnModel columnModel
      User-facing column model (ported types). Mirror of the surrogate's JDK column model; bridge listeners keep them in sync.
    • defaultRenderersByColumnClass

      protected final Map<Class<?>, TableCellRenderer> defaultRenderersByColumnClass
      Per-column-class fallback renderer registry (ported types). Walks superclass chain on lookup.
    • defaultEditorsByColumnClass

      protected final Map<Class<?>, TableCellEditor> defaultEditorsByColumnClass
      Per-column-class default cell-editor registry (ported types). Walks superclass chain on lookup. Mirrors defaultRenderersByColumnClass.
    • cellEditor

      protected TableCellEditor cellEditor
      The cell editor in flight during editing (JDK cellEditor); null when not editing.
    • editingRow

      protected int editingRow
      View row/column being edited; -1 when not editing.
    • editingColumn

      protected int editingColumn
    • tableHeader

      protected JTableHeader tableHeader
      Lazy JTableHeader holder.
    • rowSelectionAllowed

      protected boolean rowSelectionAllowed
      No-Vaadin-counterpart JDK knobs round-trip on the emulator only (R_swing_is_truth-faithful) + fire PCE. The surrogate drops them per R_vaadin_first (SD_sjtable) — the asymmetric R_swing_is_truth-shadow split SJToolBar (D_jtoolbar) / JSplitPane (D_jsplitpane) / JList (D_jlist) established. Defaults match JDK JTable. `dragEnabled(true)` and `setCellSelectionEnabled` WARN (real gaps); the rest round-trip silently (R_layouts_close_enough sizing/chrome).
    • rowHeight

      protected int rowHeight
    • rowMargin

      protected int rowMargin
    • gridColor

      protected Color gridColor
    • showHorizontalLines

      protected boolean showHorizontalLines
    • showVerticalLines

      protected boolean showVerticalLines
    • autoResizeMode

      protected int autoResizeMode
    • selectionForeground

      protected Color selectionForeground
    • selectionBackground

      protected Color selectionBackground
    • preferredViewportSize

      protected Dimension preferredViewportSize
    • dataModel

      protected TableModel dataModel
    • selectionModel

      protected ListSelectionModel selectionModel
    • autoCreateColumnsFromModel

      protected boolean autoCreateColumnsFromModel
    • cellSelectionEnabled

      protected boolean cellSelectionEnabled
  • Constructor Details

  • Method Details

    • createDefaultSelectionModel

      protected ListSelectionModel createDefaultSelectionModel()
      Returns the default selection model object, which is a DefaultListSelectionModel. A subclass can override this to return a different selection model object.
    • reconcileFields

      public final void reconcileFields()
      D_field_write_reconcile repair hook — see JSlider.reconcileFields().
      Specified by:
      reconcileFields in interface FieldReconciler.Reconcilable
    • getModel

      public TableModel getModel()
    • setModel

      public void setModel(TableModel newModel)
    • getColumnModel

      public TableColumnModel getColumnModel()
    • setColumnModel

      public void setColumnModel(TableColumnModel newModel)
    • getSelectionModel

      public ListSelectionModel getSelectionModel()
      The row selection model, in view rows (JDK contract, D_jtable_selection).
    • setSelectionModel

      public void setSelectionModel(ListSelectionModel newModel)
      Installs the row selection model. It holds view rows, as the JDK's does; the table re-maps it through the sorter when rows re-sort or the model changes, and mirrors it onto the surrogate's model-row selection that drives the Grid (D_jtable_selection).
    • getRowCount

      public int getRowCount()
      The number of rows the table shows — the sorter's view count when one is installed (JDK contract).
    • getColumnCount

      public int getColumnCount()
    • getColumnName

      public String getColumnName(int column)
    • getColumnClass

      public Class<?> getColumnClass(int column)
    • getValueAt

      public Object getValueAt(int row, int column)
    • setValueAt

      public void setValueAt(Object aValue, int row, int column)
    • isCellEditable

      public boolean isCellEditable(int row, int column)
    • convertColumnIndexToView

      public int convertColumnIndexToView(int modelColumnIndex)
    • convertColumnIndexToModel

      public int convertColumnIndexToModel(int viewColumnIndex)
    • convertRowIndexToView

      public int convertRowIndexToView(int modelRowIndex)
    • convertRowIndexToModel

      public int convertRowIndexToModel(int viewRowIndex)
    • getDefaultRenderer

      public TableCellRenderer getDefaultRenderer(Class<?> columnClass)
    • setDefaultRenderer

      public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer)
    • getCellRenderer

      public TableCellRenderer getCellRenderer(int row, int column)
      JDK contract: column-specific renderer when the TableColumn.getCellRenderer() is non-null, else fallback to the getDefaultRenderer(Class) for the column's class.
    • prepareRenderer

      public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
      Prepares the renderer's component for a cell, seeded with the cell value and selection state (JDK contract). Symmetric with prepareEditor(TableCellEditor, int, int).

      Returns an emulator component per R_no_vaadin_in_api — the renderer's own output, unsnapshotted, so a migrated subclass override receives the same thing java.awt.Component-typed JDK code expects and can post-tweak it. The render path calls through here (D_r12_provenance) rather than reaching for the renderer directly, so such an override actually runs.

    • getTableHeader

      public JTableHeader getTableHeader()
    • setTableHeader

      public void setTableHeader(JTableHeader tableHeader)
    • createDefaultTableHeader

      protected JTableHeader createDefaultTableHeader()
    • setRowSelectionInterval

      public void setRowSelectionInterval(int index0, int index1)
    • addRowSelectionInterval

      public void addRowSelectionInterval(int index0, int index1)
    • removeRowSelectionInterval

      public void removeRowSelectionInterval(int index0, int index1)
    • clearSelection

      public void clearSelection()
    • getSelectedRow

      public int getSelectedRow()
    • getSelectedRows

      public int[] getSelectedRows()
    • getSelectedRowCount

      public int getSelectedRowCount()
    • isRowSelected

      public boolean isRowSelected(int row)
    • selectAll

      public void selectAll()
    • setSelectionMode

      public void setSelectionMode(int selectionMode)
    • getRowSelectionAllowed

      public boolean getRowSelectionAllowed()
    • setRowSelectionAllowed

      public void setRowSelectionAllowed(boolean v)
    • getColumnSelectionAllowed

      public boolean getColumnSelectionAllowed()
    • setColumnSelectionAllowed

      public void setColumnSelectionAllowed(boolean v)
    • getCellSelectionEnabled

      public boolean getCellSelectionEnabled()
    • setCellSelectionEnabled

      public void setCellSelectionEnabled(boolean v)
      Vaadin Grid has no per-cell selection — WARN, but round-trip the two backing flags per JDK so getCellSelectionEnabled stays honest, and fire "cellSelectionEnabled" (D_owed_events).

      The JDK keeps a cellSelectionEnabled field that getCellSelectionEnabled() never reads — that getter derives from the two allowed-flags — so its only purpose is to supply this event's old value, and it can drift from the derived answer. Reproduced as the JDK has it rather than as it reads.

    • addColumn

      public void addColumn(TableColumn aColumn)
    • removeColumn

      public void removeColumn(TableColumn aColumn)
    • moveColumn

      public void moveColumn(int columnIndex, int newIndex)
    • getColumn

      public TableColumn getColumn(Object identifier)
    • getAutoCreateColumnsFromModel

      public boolean getAutoCreateColumnsFromModel()
    • setAutoCreateColumnsFromModel

      public void setAutoCreateColumnsFromModel(boolean autoCreate)
    • getAutoCreateRowSorter

      public boolean getAutoCreateRowSorter()
    • setAutoCreateRowSorter

      public void setAutoCreateRowSorter(boolean autoCreateRowSorter)
    • getRowSorter

      public RowSorter<? extends TableModel> getRowSorter()
    • setRowSorter

      public void setRowSorter(RowSorter<? extends TableModel> sorter)
      Installs sorter and clears the selection. The table listens to it through a JTable.SortManager, as the JDK's does, so sorterChanged runs for every sorter however it was installed (R_no_vaadin_in_api limb 2); the surrogate drives the Grid off the same instance (SD_sjtable_sorting).
    • sorterChanged

      public void sorterChanged(RowSorterEvent e)
      The current sorter re-sorted, or re-filtered. Re-maps the selection and the editing row through the sort, as the JDK does (D_jtable_selection); the Grid follows on its own, since the surrogate listens to the same sorter.

      A browser header click reaches here from inside the Grid's data fetch, which runs while the response is written and outside EHelper.callSwing — so a ListSelectionListener fired by that re-map cannot open a modal dialog.

      Specified by:
      sorterChanged in interface RowSorterListener
    • getUpdateSelectionOnSort

      public boolean getUpdateSelectionOnSort()
    • setUpdateSelectionOnSort

      public void setUpdateSelectionOnSort(boolean update)
    • getRowHeight

      public int getRowHeight()
    • setRowHeight

      public void setRowHeight(int rowHeight)
    • getRowHeight

      public int getRowHeight(int row)
    • setRowHeight

      public void setRowHeight(int row, int rowHeight)
    • getRowMargin

      public int getRowMargin()
    • setRowMargin

      public void setRowMargin(int rowMargin)
    • getIntercellSpacing

      public Dimension getIntercellSpacing()
    • setIntercellSpacing

      public void setIntercellSpacing(Dimension intercellSpacing)
      Splits the pair the way the JDK does — height to setRowMargin(int), width to the column model's columnMargin — so the notification is the "rowMargin" PCE plus the column model's COLUMN_MARGIN_CHANGED ChangeEvent. "intercellSpacing" is not a bound property (D_property_fanout_audit), and there is no field behind it: the getter recomposes the Dimension from the two margins, as the JDK's does.
    • getGridColor

      public Color getGridColor()
    • setGridColor

      public void setGridColor(Color gridColor)
    • getShowHorizontalLines

      public boolean getShowHorizontalLines()
    • setShowHorizontalLines

      public void setShowHorizontalLines(boolean v)
    • getShowVerticalLines

      public boolean getShowVerticalLines()
    • setShowVerticalLines

      public void setShowVerticalLines(boolean v)
    • getShowGrid

      public boolean getShowGrid()
    • setShowGrid

      public void setShowGrid(boolean v)
    • getAutoResizeMode

      public int getAutoResizeMode()
    • setAutoResizeMode

      public void setAutoResizeMode(int mode)
    • getSelectionForeground

      public Color getSelectionForeground()
    • setSelectionForeground

      public void setSelectionForeground(Color c)
    • getSelectionBackground

      public Color getSelectionBackground()
    • setSelectionBackground

      public void setSelectionBackground(Color c)
    • getCellRect

      public Rectangle getCellRect(int row, int column, boolean includeSpacing)
      The JDK's geometry over this table's nominal state: getRowHeight() and the column model's widths and margins. It is not where the browser drew the cell (R_layouts_close_enough), and a row or column out of range reads getWidth() / getHeight(), which are unimplemented and answer 0.
    • getDragEnabled

      public boolean getDragEnabled()
    • setDragEnabled

      public void setDragEnabled(boolean v)
    • getDropMode

      public final DropMode getDropMode()
    • setDropMode

      public final void setDropMode(DropMode dropMode)
    • getFillsViewportHeight

      public boolean getFillsViewportHeight()
    • setFillsViewportHeight

      public void setFillsViewportHeight(boolean v)
    • getPreferredScrollableViewportSize

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

      public void setPreferredScrollableViewportSize(Dimension size)
    • editCellAt

      public void editCellAt(int row, int column)
    • editCellAt

      public boolean editCellAt(int row, int column, EventObject e)
      Starts single-column editing (D_jtable_cell_editing): resolves the cell's editor, seeds its component, sets it as the editor component on only the clicked column, and opens the inherited Grid.Editor. Value flows through the Swing editor lifecycle — commit (editingStopped) writes back via setValueAt(Object, int, int); cancel (editingCanceled) discards.

      row is a view row (JDK contract). All model access here goes through the view-indexed public accessors (getValueAt(int, int) / isCellEditable(int, int) / setValueAt(Object, int, int)), and editingRow is stored as the view row; only itemForRow and the editor-row snapshot loop convert to the model row the Grid item carries (D_jtable_cell_editing).

    • isEditing

      public boolean isEditing()
    • getEditingRow

      public int getEditingRow()
      The row being edited as a view row (JDK contract), or -1 (D_jtable_cell_editing).
    • getEditingColumn

      public int getEditingColumn()
    • getEditorComponent

      public Component getEditorComponent()
    • removeEditor

      public void removeEditor()
      Tears down the in-flight edit without writing back (JDK contract: no commit).
    • editingStopped

      public void editingStopped(ChangeEvent e)
      Editing finished — commit the value.
      Specified by:
      editingStopped in interface CellEditorListener
    • editingCanceled

      public void editingCanceled(ChangeEvent e)
      Editing abandoned — tear down without writing back.
      Specified by:
      editingCanceled in interface CellEditorListener
    • getDefaultEditor

      public TableCellEditor getDefaultEditor(Class<?> columnClass)
      JDK contract: default editor for a column class, walking the superclass chain then falling back to the Object.class editor. Mirrors getDefaultRenderer(Class).
    • setDefaultEditor

      public void setDefaultEditor(Class<?> columnClass, TableCellEditor editor)
    • getCellEditor

      public TableCellEditor getCellEditor(int row, int column)
      JDK contract: the column's own TableColumn.getCellEditor() when set, else the getDefaultEditor(Class) for the column class. Mirrors getCellRenderer(int, int).
    • getCellEditor

      public TableCellEditor getCellEditor()
      The editor in flight during editing (JDK cellEditor); null when not editing.
    • setCellEditor

      public void setCellEditor(TableCellEditor anEditor)
    • prepareEditor

      public Component prepareEditor(TableCellEditor editor, int row, int column)
      Prepares the editor's component for a cell, seeded with the cell value (JDK contract). The interactive open path (editCellAt / isEditing / …) lands with the Grid.Editor bridge (D_jtable_cell_editing, Slice 2); resolution + prepare are wired now.
    • tableChanged

      public void tableChanged(TableModelEvent e)
      Invoked when this table's TableModel generates a TableModelEvent, which is in model coordinates. The table is the model's listener, as the JDK's is: it adjusts the view selection and the editing row — through the sort bookkeeping when a sorter is installed — and hands the change to the surrogate, which tells the sorter and refreshes the Grid. A subclass overriding this without calling super stops the table following its model, as it would in the JDK.
      Specified by:
      tableChanged in interface TableModelListener
    • valueChanged

      public void valueChanged(ListSelectionEvent e)
      Invoked when the row selection changes. Keeps the sort bookkeeping's cached selection honest and mirrors the change onto the surrogate's model-row selection, which is what the Grid shows — the JDK's repaint, in this table's terms.
      Specified by:
      valueChanged in interface ListSelectionListener
    • columnAdded

      public void columnAdded(TableColumnModelEvent e)
      Specified by:
      columnAdded in interface TableColumnModelListener
    • columnRemoved

      public void columnRemoved(TableColumnModelEvent e)
      Specified by:
      columnRemoved in interface TableColumnModelListener
    • columnMoved

      public void columnMoved(TableColumnModelEvent e)
      Specified by:
      columnMoved in interface TableColumnModelListener
    • columnMarginChanged

      public void columnMarginChanged(ChangeEvent e)
      Specified by:
      columnMarginChanged in interface TableColumnModelListener
    • columnSelectionChanged

      public void columnSelectionChanged(ListSelectionEvent e)
      Specified by:
      columnSelectionChanged in interface TableColumnModelListener
    • getScrollableUnitIncrement

      public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
      Specified by:
      getScrollableUnitIncrement in interface Scrollable
    • getScrollableBlockIncrement

      public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
      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
    • doLayout

      public void doLayout()
      Overrides:
      doLayout in class Container
    • sizeColumnsToFit

      public void sizeColumnsToFit(int resizingColumn)
    • sizeColumnsToFit

      public void sizeColumnsToFit(boolean lastColumnOnly)
    • rowAtPoint

      public int rowAtPoint(Point point)
      The clicked view row during a mouse handler's dispatch, -1 otherwise, whatever the coordinates. The rest is the JDK's body, so a table shrunk while the handler was parked answers -1.
    • columnAtPoint

      public int columnAtPoint(Point point)
      The clicked view column during a mouse handler's dispatch, -1 otherwise (or for a row-only click) — see rowAtPoint(Point).
    • print

      public boolean print()
    • print

      public boolean print(JTable.PrintMode printMode)
    • getUIClassID

      public String getUIClassID()
      Overrides:
      getUIClassID in class JComponent
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JComponent
    • getUI

      public TableUI getUI()
      Overrides:
      getUI in class JComponent
    • setUI

      public void setUI(TableUI ui)
    • getAccessibleContext

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