Class ViewHugeTableModel
- All Implemented Interfaces:
TableModel
The point of this is for displaying tables with very large row counts
in a JTable.
Since the default height of a JTable row is 16 pixels
(see JTable.getRowHeight()) a JTable component
with more than 2^27 rows (about 134 million) will have a height
in pixels which is too large to represent in a 32-bit int.
In that case Swing gives up and just doesn't display the thing.
This class implements a model of a fixed (large but not too large)
size, VIEWSIZE rows, which at any one time gives a view of
a contiguous sequence of rows from the base table, starting at a
mutable value given by getViewBase(). It works out the value
of viewBase by reference to a scrollbar which is owned by
this model, and assumed to control vertical scrolling of the
scroll panel displaying the JTable that views it.
The viewBase value is updated dynamically according to the current
state (position) of the scrollbar. Whenever the viewBase changes,
listeners (most importantly the client JTable) are notified.
In principle, every time the scrollbar position, or equivalently the set of currently visible rows, changes, the viewBase should change. But since the scrollbar has only pixel resolution, smallish changes can be accommodated without needing to take the somewhat expensive step of changing the viewBase.
The underlying table model can still only have up to 2^31 rows. The general approach used here would work for larger underlying row data, but it would be necessary to define a new long-capable TableModel interface to accommodate such data.
It is not recommended to use this class for underlying table models which are not in fact huge.
Note this class will only help you for displaying a JTable within a scrollpane. If you want to display a giga-row JTable unscrolled on a 100km tall VDU, you're on your own.
- Since:
- 16 Jul 2014
- Author:
- Mark Taylor
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of property giving underlying value of first row of this model.static final intFixed number of rows displayed by this model. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty model.ViewHugeTableModel(TableModel hugeModel, JScrollBar vbar) Constructs a configured model. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener that will be notified about ViewBase changes.voidvoidconfigureModel(TableModel hugeModel, JScrollBar vbar) Sets this mode up for use with a given underlying table model and scroll bar.protected voidNotifies property change listeners of a property change.protected voidNotifies table model listeners of a table model event.Class<?>getColumnClass(int icol) intgetColumnName(int icol) intgetHugeRow(int iViewRow) Returns the row in the underlying huge model corresponding to a given row in this view.intgetValueAt(int irow, int icol) intReturns the offset from which this view views the underlying table model.booleanisCellEditable(int irow, int icol) voidRemoves a listener added earlier.voidvoidsetValueAt(Object value, int irow, int icol)
-
Field Details
-
VIEWBASE_PROPERTY
Name of property giving underlying value of first row of this model.- See Also:
-
VIEWSIZE
public static final int VIEWSIZEFixed number of rows displayed by this model.- See Also:
-
-
Constructor Details
-
ViewHugeTableModel
public ViewHugeTableModel()Constructs an empty model. -
ViewHugeTableModel
Constructs a configured model.- Parameters:
hugeModel- table model with more than VIEWSIZE rowsvbar- scrollbar used to control vertical scrolling of table view
-
-
Method Details
-
configureModel
Sets this mode up for use with a given underlying table model and scroll bar.- Parameters:
hugeModel- table model with more than VIEWSIZE rowsvbar- scrollbar used to control vertical scrolling of table view
-
getRowCount
public int getRowCount()- Specified by:
getRowCountin interfaceTableModel
-
getValueAt
- Specified by:
getValueAtin interfaceTableModel
-
setValueAt
- Specified by:
setValueAtin interfaceTableModel
-
isCellEditable
public boolean isCellEditable(int irow, int icol) - Specified by:
isCellEditablein interfaceTableModel
-
getColumnCount
public int getColumnCount()- Specified by:
getColumnCountin interfaceTableModel
-
getColumnName
- Specified by:
getColumnNamein interfaceTableModel
-
getColumnClass
- Specified by:
getColumnClassin interfaceTableModel
-
addTableModelListener
- Specified by:
addTableModelListenerin interfaceTableModel
-
removeTableModelListener
- Specified by:
removeTableModelListenerin interfaceTableModel
-
getViewBase
public int getViewBase()Returns the offset from which this view views the underlying table model. Changes in this value will be notified to registered PropertyChangeListeners.- Returns:
- view base
-
addPropertyChangeListener
Adds a listener that will be notified about ViewBase changes. These have the property nameVIEWBASE_PROPERTY.- Parameters:
lnr- listener to add
-
removePropertyChangeListener
Removes a listener added earlier.- Parameters:
lnr- listener to remove
-
fireTableChanged
Notifies table model listeners of a table model event.- Parameters:
evt- event
-
firePropertyChanged
Notifies property change listeners of a property change.- Parameters:
evt- event
-
getHugeRow
public int getHugeRow(int iViewRow) Returns the row in the underlying huge model corresponding to a given row in this view.- Returns:
iViewRow + viewBase
-