public class ViewHugeTableModel
extends java.lang.Object
implements javax.swing.table.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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
VIEWBASE_PROPERTY
Name of property giving underlying value of first row of this model.
|
static int |
VIEWSIZE
Fixed number of rows displayed by this model.
|
Constructor and Description |
---|
ViewHugeTableModel()
Constructs an empty model.
|
ViewHugeTableModel(javax.swing.table.TableModel hugeModel,
javax.swing.JScrollBar vbar)
Constructs a configured model.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener lnr)
Adds a listener that will be notified about ViewBase changes.
|
void |
addTableModelListener(javax.swing.event.TableModelListener lnr) |
void |
configureModel(javax.swing.table.TableModel hugeModel,
javax.swing.JScrollBar vbar)
Sets this mode up for use with a given underlying table model and
scroll bar.
|
protected void |
firePropertyChanged(java.beans.PropertyChangeEvent evt)
Notifies property change listeners of a property change.
|
protected void |
fireTableChanged(javax.swing.event.TableModelEvent evt)
Notifies table model listeners of a table model event.
|
java.lang.Class<?> |
getColumnClass(int icol) |
int |
getColumnCount() |
java.lang.String |
getColumnName(int icol) |
int |
getHugeRow(int iViewRow)
Returns the row in the underlying huge model corresponding to a given
row in this view.
|
int |
getRowCount() |
java.lang.Object |
getValueAt(int irow,
int icol) |
int |
getViewBase()
Returns the offset from which this view views the underlying
table model.
|
boolean |
isCellEditable(int irow,
int icol) |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener lnr)
Removes a listener added earlier.
|
void |
removeTableModelListener(javax.swing.event.TableModelListener lnr) |
void |
setValueAt(java.lang.Object value,
int irow,
int icol) |
public static final java.lang.String VIEWBASE_PROPERTY
public static final int VIEWSIZE
public ViewHugeTableModel()
public ViewHugeTableModel(javax.swing.table.TableModel hugeModel, javax.swing.JScrollBar vbar)
hugeModel
- table model with more than VIEWSIZE rowsvbar
- scrollbar used to control vertical scrolling of
table viewpublic void configureModel(javax.swing.table.TableModel hugeModel, javax.swing.JScrollBar vbar)
hugeModel
- table model with more than VIEWSIZE rowsvbar
- scrollbar used to control vertical scrolling of
table viewpublic int getRowCount()
getRowCount
in interface javax.swing.table.TableModel
public java.lang.Object getValueAt(int irow, int icol)
getValueAt
in interface javax.swing.table.TableModel
public void setValueAt(java.lang.Object value, int irow, int icol)
setValueAt
in interface javax.swing.table.TableModel
public boolean isCellEditable(int irow, int icol)
isCellEditable
in interface javax.swing.table.TableModel
public int getColumnCount()
getColumnCount
in interface javax.swing.table.TableModel
public java.lang.String getColumnName(int icol)
getColumnName
in interface javax.swing.table.TableModel
public java.lang.Class<?> getColumnClass(int icol)
getColumnClass
in interface javax.swing.table.TableModel
public void addTableModelListener(javax.swing.event.TableModelListener lnr)
addTableModelListener
in interface javax.swing.table.TableModel
public void removeTableModelListener(javax.swing.event.TableModelListener lnr)
removeTableModelListener
in interface javax.swing.table.TableModel
public int getViewBase()
public void addPropertyChangeListener(java.beans.PropertyChangeListener lnr)
VIEWBASE_PROPERTY
.lnr
- listener to addpublic void removePropertyChangeListener(java.beans.PropertyChangeListener lnr)
lnr
- listener to removeprotected void fireTableChanged(javax.swing.event.TableModelEvent evt)
evt
- eventprotected void firePropertyChanged(java.beans.PropertyChangeEvent evt)
evt
- eventpublic int getHugeRow(int iViewRow)
iViewRow + viewBase