Interface BasicTableModel
- All Superinterfaces:
TableModel
UI.table( conf -> conf
.colNames("A", "B")
.colCount(()->2)
.rowCount(()->3)
.getsEntryAt((int row, int col)->
vm.getDataAt(row, col)
)
)
Note that TableData is the recommended way of modelling a table in
SwingTree. It is a single immutable value describing the whole table (cells,
column names, column classes, cell order and editability), which you hold in a
Var property and bind through UIFactoryMethods.table(sprouts.Var):
Var<TableData> data = Var.of(
TableData.of(UI.CellOrder.ROW_MAJOR, "A", "B")
.addRow(1, 2)
);
UI.table(data);
A table bound like that updates itself whenever the property changes (so there is
no updateOn(..) to remember), it is thread safe by construction, and it
syncs row changes to the JTable incrementally instead of
rebuilding it. The lambda based model below, by contrast, is read live,
which is why SwingTree has to copy the whole table on every refresh under the
EventProcessor.DECOUPLED protocol.
Note that an implementation of this interface is merely a description of where
the table data lives, it is not the model which the JTable ends up
talking to. SwingTree always wraps it in a thread safe model of its own, which
reads through the methods declared here and, under the
EventProcessor.DECOUPLED protocol, keeps a UI thread
owned snapshot of them so that the AWT Event Dispatch Thread never reads your
application thread owned state while it paints. This is also why you should not
expect JTable.getModel() to return the very object you passed
to withModel(..).
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classThe class below is a functional builder for creating a lambda based implementation of theBasicTableModel.static interfaceImplementations of this functional interface translate to theTableModel.isCellEditable(int, int)method.static interfaceImplementations of this functional interface translate to theTableModel.getColumnClass(int)method.static interfaceImplementations of this functional interface translate to theTableModel.getColumnCount()method.static interfaceImplementations of this functional interface translate to theTableModel.getColumnName(int)method.static interfaceImplementations of this functional interface translate to theTableModel.getValueAt(int, int)method.static interfaceImplementations of this functional interface translate to theTableModel.setValueAt(Object, int, int)method.static interfaceImplementations of this functional interface translate to theTableModel.getRowCount()method. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidRegisters a listener which wants to be told when the data of this model changed.default Class<?> getColumnClass(int columnIndex) intdefault StringgetColumnName(int columnIndex) intgetValueAt(int rowIndex, int columnIndex) default booleanisCellEditable(int rowIndex, int columnIndex) default voidUnregisters a listener previously registered throughaddTableModelListener(TableModelListener).voidsetValueAt(Object aValue, int rowIndex, int columnIndex)
-
Method Details
-
getRowCount
int getRowCount()- Specified by:
getRowCountin interfaceTableModel
-
getColumnCount
int getColumnCount()- Specified by:
getColumnCountin interfaceTableModel
-
getValueAt
- Specified by:
getValueAtin interfaceTableModel
-
setValueAt
- Specified by:
setValueAtin interfaceTableModel
-
getColumnClass
- Specified by:
getColumnClassin interfaceTableModel
-
getColumnName
- Specified by:
getColumnNamein interfaceTableModel
-
isCellEditable
default boolean isCellEditable(int rowIndex, int columnIndex) - Specified by:
isCellEditablein interfaceTableModel
-
addTableModelListener
Registers a listener which wants to be told when the data of this model changed.A
BasicTableModelis a plain description of where the table data comes from, which SwingTree wraps in a thread safe model of its own before handing it to aJTable. That wrapper is the only listener you will ever see here, and it uses this to learn that it has to re-read the data. The default implementation ignores the listener, which is what you want for a model that never signals changes on its own (useupdateTableOn(..)on the table builder, orBasicTableModel.Builder.updateOn(Observable), in that case).- Specified by:
addTableModelListenerin interfaceTableModel- Parameters:
l- The listener which wants to be told about changes to the data of this model.
-
removeTableModelListener
Unregisters a listener previously registered throughaddTableModelListener(TableModelListener). The default implementation does nothing, mirroring the default ofaddTableModelListener(TableModelListener).- Specified by:
removeTableModelListenerin interfaceTableModel- Parameters:
l- The listener which no longer wants to be told about changes to the data of this model.
-