|
|||||||||
| 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 | |
|---|---|
class |
AdvancedJTable.InnerTableColumnModel
InnerTableColumnModel extends DefaultTableColumnModel in order to make the first column of the TreeTable not reorderable (optionally). |
protected class |
AdvancedJTable.InnerTableHeader
This class extends FilterTableHeader in order to cater for the last dummy column and to make the first column not reorderable (optionally). |
| 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 boolean |
isFirstColumnFixed
boolean flag to indicate whether the first column of the table is fixed. |
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 a new instance of InnerTableColumnModel. |
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 (InnerTableHeader), 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. |
TableAssistant |
getTableAssistant()
Returns the table assistant instance associated with this table. |
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. |
protected void |
initializeLocalVars()
Initializes table properties to their default values. |
boolean |
isCellEditable(int row,
int column)
Returns true if the cell at row and column
is editable. |
boolean |
isDummyColumn(int column)
Determines if the supplied column is the last dummy column. |
boolean |
isFirstColumnFixed()
Determines whether the first column of the table can be removed or reordered. |
Component |
prepareRenderer(TableCellRenderer renderer,
int row,
int column)
Prepares the renderer by querying the data model for the value and selection state of the cell at row, column. |
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 |
setEvenColor(Color evenColor)
Sets the color for painting the even rows of the table to all the renderers contained in the defaultRenderersByColumnClass Hashtable (provided the renderer is an instance of DefaultRenderer. |
void |
setFirstColumnFixed(boolean isFirstColumnFixed)
Assigns a boolean flag that is true if the first column of the table can be removed or reordered. |
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 |
setOddColor(Color oddColor)
Sets the color for painting the odd rows of the table to all the renderers contained in the defaultRenderersByColumnClass Hashtable (provided the renderer is an instance of DefaultRenderer. |
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 transient TableReorder tableReorder
protected boolean isFirstColumnFixed
| 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 JTableJTable.addNotify()protected TableColumnModel createDefaultColumnModel()
DefaultTableColumnModel. A subclass can override this
method to return a different column model object.
createDefaultColumnModel in class JTableDefaultTableColumnModelpublic 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 JTableJTable.getAutoCreateColumnsFromModel()protected void createDefaultEditors()
createDefaultEditors in class JTableDefaultCellEditorprotected void createDefaultRenderers()
createDefaultRenderers in class JTableDefaultTableCellRendererprotected JTableHeader createDefaultTableHeader()
createDefaultTableHeader in class JTableJTableHeaderprotected TableReorder createReorder()
public Class getColumnClass(int column)
column.
getColumnClass in class JTablecolumn - the column in the view being queried
column
in the view where the first column is column 0public boolean getShowDummyColumn()
public TableAssistant getTableAssistant()
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 JTablerow - the row whose value is to be queriedcolumn - the column whose value is to be queried
protected void initializeLocalVars()
initializeLocalVars in class JTable
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 JTablerow - the row whose value is to be queriedcolumn - the column whose value is to be queried
JTable.setValueAt(java.lang.Object, int, int)public boolean isDummyColumn(int column)
column - the index of the table column
public boolean isFirstColumnFixed()
public Component prepareRenderer(TableCellRenderer renderer,
int row,
int column)
javax.swing.JTablerow, column.
Returns the component (may be a Component
or a JComponent) under the event location.
Note: Throughout the table package, the internal implementations always use this method to prepare renderers so that this default behavior can be safely overridden by a subclass.
prepareRenderer in class JTablerenderer - the TableCellRenderer to preparerow - the row of the cell to render, where 0 is the first rowcolumn - the column of the cell to render,
where 0 is the first column
Component under the event locationpublic 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 JComponentaRect - the visible RectangleJViewportpublic 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 JTablenewModel - the new data source for this tableJTable.getColumnModel()public void setEvenColor(Color evenColor)
DefaultRenderer.
evenColor - the even row colorpublic void setFirstColumnFixed(boolean isFirstColumnFixed)
isFirstColumnFixed - a boolean which is true if we are able to remove or reorder the first column.public void setModel(TableModel model)
newModel and registers
with it for listener notifications from the new data model.
setModel in class JTablemodel - the new data source for this tableJTable.getModel()public void setOddColor(Color oddColor)
DefaultRenderer.
oddColor - the odd row colorpublic 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 JTablenewHeader - 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 TableModelListenertableChanged in class JTablepublic void updateUI()
UIManager that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager.
updateUI in class JTableJComponent.updateUI()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||