|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTable
com.sciapp.table.AdvancedJTable
public class AdvancedJTable
AdvancedJTable is a sublass of JTable that makes full use of classes contained in this library, so as to add extra functionality to the JTable Swing component.
The most important features that were added are:
1) There is the option to add a dummy column to the table header with no data underneath,
for decorative purposes. This option is available if the table is enclosed by
an AdvancedJScrollPane, in which case, it can be controlled with setShowDummyColumn
.
2) Define default editors and renderers to those in the com.sciapp.editors and com.sciapp.renderers respectively
3) Autoresize table columns upon double-clicking on a table column border. (see TableAssistant
)
4) Display a popup through which the columns of the table can be dynamically added/removed. (see TableAssistant
)
5) Use a table header whose columns cannot be reordered with right mouse button clicks. (see AdvancedTableHeader
)
6) Correctly handle selection changes when the tabular data are restructured. (see TableReorder
)
7) Programmatically alter the table columns displayed and their widths. (see setTableState(java.lang.String)
)
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JTable |
---|
JTable.AccessibleJTable |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected TableReorder |
tableReorder
This is the TableReorder object. |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
AdvancedJTable()
Constructs a default AdvancedJTable which is initialized with a default data model, a default column model, and a default selection model. |
|
AdvancedJTable(int numRows,
int numColumns)
Constructs an AdvancedJTable with numRows and numColumns of empty cells using the DefaultTableModel. |
|
AdvancedJTable(Object[][] rowData,
Object[] columnNames)
Constructs an AdvancedJTable to display the values in the two dimensional array, rowData, with column names, columnNames. |
|
AdvancedJTable(TableModel dm)
Constructs a JTable which is initialized with dm as the data model, a default column model, and a default selection model. |
|
AdvancedJTable(TableModel dm,
TableColumnModel cm)
Constructs an AdvancedJTable which is initialized with dm as the data model, cm as the column model, and a default selection model. |
|
AdvancedJTable(TableModel dm,
TableColumnModel cm,
ListSelectionModel sm)
Constructs an AdvancedJTable which is initialized with dm as the data model, cm as the column model, and sm as the selection model. |
|
AdvancedJTable(Vector rowData,
Vector columnNames)
Constructs an AdvancedJTable to display the values in the Vector of Vectors, rowData, with column names, columnNames. |
Method Summary | |
---|---|
protected void |
configureEnclosingScrollPane()
If this JTable is the viewportView of an enclosing JScrollPane
(the usual situation), configure this ScrollPane by, amongst other things,
installing the table's tableHeader as the columnHeaderView of the scroll pane. |
protected TableColumnModel |
createDefaultColumnModel()
Returns the default column model object, which is a DefaultTableColumnModel . |
void |
createDefaultColumnsFromModel()
Creates default columns for the table from the data model using the getColumnCount method
defined in the TableModel interface. |
protected void |
createDefaultEditors()
Creates default cell editors for objects, numbers, and boolean values. |
protected void |
createDefaultRenderers()
Creates default cell renderers for objects, numbers, doubles, dates, booleans, and icons. |
protected JTableHeader |
createDefaultTableHeader()
Returns the default table header object which is a customized AdvancedTableHeader that takes into account the last dummy column. |
protected TableReorder |
createReorder()
Returns the TableReorder that will handle table selection changes. |
Class |
getColumnClass(int column)
Returns the type of the column appearing in the view at column position column . |
boolean |
getShowDummyColumn()
Determines whether the table is set to show the dummy column. |
String |
getTableState()
Returns a string showing which columns are shown and their corresponding widths. |
Object |
getValueAt(int row,
int column)
Returns the cell value at row and column . |
boolean |
isCellEditable(int row,
int column)
Returns true if the cell at row and column
is editable. |
void |
scrollRectToVisible(Rectangle aRect)
Forwards the scrollRectToVisible() message to the
JComponent 's parent. |
void |
setColumnModel(TableColumnModel newModel)
Sets the column model for this table to newModel and registers
for listener notifications from the new column model. |
void |
setModel(TableModel model)
Sets the data model for this table to newModel and registers
with it for listener notifications from the new data model. |
void |
setShowDummyColumn(boolean showDummyColumn)
Sets this table's showLastColumn flag. |
void |
setTableHeader(JTableHeader newHeader)
Sets the tableHeader working with this JTable to newHeader . |
void |
setTableState(String state)
Set which columns will be shown and their corresponding widths. |
void |
tableChanged(TableModelEvent e)
Invoked when this table's TableModel generates
a TableModelEvent . |
void |
updateUI()
Notification from the UIManager that the L&F has changed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected TableReorder tableReorder
Constructor Detail |
---|
public AdvancedJTable()
public AdvancedJTable(Object[][] rowData, Object[] columnNames)
rowData[1][5];
All rows must be of the same length as columnNames.
public AdvancedJTable(int numRows, int numColumns)
public AdvancedJTable(Vector rowData, Vector columnNames)
((Vector)rowData.elementAt(1)).elementAt(5);
All rows must be of the same length as columnNames.
public AdvancedJTable(TableModel dm)
public AdvancedJTable(TableModel dm, TableColumnModel cm)
public AdvancedJTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
Method Detail |
---|
protected void configureEnclosingScrollPane()
JTable
is the viewportView
of an enclosing JScrollPane
(the usual situation), configure this ScrollPane
by, amongst other things,
installing the table's tableHeader
as the columnHeaderView
of the scroll pane.
When a JTable
is added to a JScrollPane
in the usual way,
using new JScrollPane(myTable)
, addNotify
is
called in the JTable
(when the table is added to the viewport).
JTable
's addNotify
method in turn calls this method,
which is protected so that this default installation procedure can
be overridden by a subclass.
configureEnclosingScrollPane
in class JTable
JTable.addNotify()
protected TableColumnModel createDefaultColumnModel()
DefaultTableColumnModel
. A subclass can override this
method to return a different column model object.
createDefaultColumnModel
in class JTable
DefaultTableColumnModel
public void createDefaultColumnsFromModel()
getColumnCount
method
defined in the TableModel
interface.
Clears any existing columns before creating the new columns based on information from the model.
createDefaultColumnsFromModel
in class JTable
JTable.getAutoCreateColumnsFromModel()
protected void createDefaultEditors()
createDefaultEditors
in class JTable
DefaultCellEditor
protected void createDefaultRenderers()
createDefaultRenderers
in class JTable
DefaultTableCellRenderer
protected JTableHeader createDefaultTableHeader()
createDefaultTableHeader
in class JTable
JTableHeader
protected TableReorder createReorder()
public Class getColumnClass(int column)
column
.
getColumnClass
in class JTable
column
- the column in the view being queried
column
in the view where the first column is column 0public boolean getShowDummyColumn()
public String getTableState()
public Object getValueAt(int row, int column)
row
and column
.
Note: The column is specified in the table view's display
order, and not in the TableModel
's column
order. This is an important distinction because as the
user rearranges the columns in the table,
the column at a given index in the view will change.
Meanwhile the user's actions never affect the model's
column ordering.
getValueAt
in class JTable
row
- the row whose value is to be queriedcolumn
- the column whose value is to be queried
public boolean isCellEditable(int row, int column)
row
and column
is editable. Otherwise, invoking setValueAt
on the cell
will have no effect.
Note: The column is specified in the table view's display
order, and not in the TableModel
's column
order. This is an important distinction because as the
user rearranges the columns in the table,
the column at a given index in the view will change.
Meanwhile the user's actions never affect the model's
column ordering.
isCellEditable
in class JTable
row
- the row whose value is to be queriedcolumn
- the column whose value is to be queried
JTable.setValueAt(java.lang.Object, int, int)
public void scrollRectToVisible(Rectangle aRect)
scrollRectToVisible()
message to the
JComponent
's parent. Components that can service
the request, such as JViewport
,
override this method and perform the scrolling.
scrollRectToVisible
in class JComponent
aRect
- the visible Rectangle
JViewport
public void setColumnModel(TableColumnModel newModel)
newModel
and registers
for listener notifications from the new column model. Also sets
the column model of the JTableHeader
to columnModel
.
setColumnModel
in class JTable
newModel
- the new data source for this tableJTable.getColumnModel()
public void setModel(TableModel model)
newModel
and registers
with it for listener notifications from the new data model.
setModel
in class JTable
model
- the new data source for this tableJTable.getModel()
public void setShowDummyColumn(boolean showDummyColumn)
public void setTableHeader(JTableHeader newHeader)
tableHeader
working with this JTable
to newHeader
.
It is legal to have a null
tableHeader
.
setTableHeader
in class JTable
newHeader
- new tableHeaderJTable.getTableHeader()
public void setTableState(String state)
state
is formatted as follows:
i1:w1,i2:w2,...
where i is the column's model index and w its width.
A column which is removed by calling this method can always be added later
if its model index is supplied. Only columns that are removed via the removeColumn method
of JTable are permanently removed from the table.
state
- a string showing which columns will be shown and their corresponding widths.public void tableChanged(TableModelEvent e)
TableModel
generates
a TableModelEvent
.
The TableModelEvent
should be constructed in the
coordinate system of the model; the appropriate mapping to the
view coordinate system is performed by this JTable
when it receives the event.
Application code will not use these methods explicitly, they
are used internally by JTable
.
Note that as of 1.3, this method clears the selection, if any.
tableChanged
in interface TableModelListener
tableChanged
in class JTable
public void updateUI()
UIManager
that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager
.
updateUI
in class JTable
JComponent.updateUI()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |