|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JScrollPane com.jidesoft.swing.JideScrollPane com.jidesoft.grid.TableScrollPane
public class TableScrollPane
TableScrollPane
is a special JideScrollPane
that supports header and footer columns or
rows. JScrollPane
supports adding a component to top area and west area. JideScrollPane
added the support to east area and bottom area. TableScrollPane
further enhances it to handle the
special case of table to allow you easily add header column(s), footer column(s), and footer to your table.
MultiTableModel
instance first. Defining MultiTableModel
is
the same as defining TableModel except you can specify which columns are header and footer.
After you create MultiTableModel
, just pass it in to the constructor of TableScrollPane. You have an
option to specify if the table is sortable. You also have an option to specify a table model for footer row. The
table created from footer table model will appear at the bottom of the table and scroll horizontally along with the
table above. The footer table model must have the same column count as the MultiTableModel excluding header and
footer columns.
Even though header columns and footer columns are added as separate components, they will work just like in one
table. For example, row selection is synchronized. Tab key or left/right arrows will navigate across all three
tables. If you scroll vertically, all three tables will scroll together. If you resize columns in any table, even the
last column of the header column table and the first column of footer column table.
Note for users of TableScrollPane before v1.8.6:In 1.8.6 release, there is a design change in TableScrollPane.
The old constructor that takes six table models as parameter is removed. The new constructors only accept one or two
MultiTableModels. If you use six table model constructor, you need to refactor your code to remove the usage of it.
JideScrollPane
,
MultiTableModel
,
Serialized FormNested Class Summary | |
---|---|
static class |
TableScrollPane.TablePosition
A class that define a table, a row index and a column index. |
Nested classes/interfaces inherited from class javax.swing.JScrollPane |
---|
JScrollPane.AccessibleJScrollPane, JScrollPane.ScrollBar |
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Fields inherited from class javax.swing.JScrollPane |
---|
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewport |
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 com.jidesoft.swing.JideScrollPaneConstants |
---|
COLUMN_FOOTER, HORIZONTAL_LEADING, HORIZONTAL_LEFT, HORIZONTAL_RIGHT, HORIZONTAL_TRAILING, ROW_FOOTER, SUB_COLUMN_HEADER, SUB_UPPER_LEFT, SUB_UPPER_RIGHT, VERTICAL_BOTTOM, VERTICAL_TOP |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
TableScrollPane()
Creates an empty TableScrollPane . |
|
TableScrollPane(MultiTableModel tableModel)
Creates a TableScrollPane . |
|
TableScrollPane(MultiTableModel tableModel,
boolean sortable)
Creates a TableScrollPane without footer table. |
|
TableScrollPane(MultiTableModel tableModel,
MultiTableModel footerTableModel)
Creates a TableScrollPane with a footer table. |
|
TableScrollPane(MultiTableModel tableModel,
MultiTableModel footerTableModel,
boolean sortable)
Creates a TableScrollPane with a footer table. |
|
TableScrollPane(MultiTableModel tableModel,
MultiTableModel footerTableModel,
boolean sortable,
boolean sync)
Creates a TableScrollPane with a footer table. |
|
TableScrollPane(MultiTableModel tableModel,
MultiTableModel footerTableModel,
boolean sortable,
int tableIndex,
boolean sync)
Creates a TableScrollPane with a footer table. |
|
TableScrollPane(MultiTableModel tableModel,
MultiTableModel headerTableModel,
MultiTableModel footerTableModel)
Creates a TableScrollPane with a header table and a footer table. |
|
TableScrollPane(MultiTableModel tableModel,
MultiTableModel headerTableModel,
MultiTableModel footerTableModel,
boolean sortable)
Creates a TableScrollPane with a header table and a footer table. |
|
TableScrollPane(MultiTableModel tableModel,
MultiTableModel headerTableModel,
MultiTableModel footerTableModel,
boolean sortable,
boolean sync)
Creates a TableScrollPane with a header table and a footer table. |
|
TableScrollPane(MultiTableModel tableModel,
MultiTableModel headerTableModel,
MultiTableModel footerTableModel,
boolean sortable,
int tableIndex,
boolean sync)
Creates a TableScrollPane with a header table and a footer table. |
Method Summary | |
---|---|
void |
changeSelection(int rowIndex,
int columnIndex,
boolean toggle,
boolean extend)
Updates the selection models of the table, depending on the state of the two flags: toggle and
extend . |
void |
clearSelection()
Deselects all selected columns and rows. |
int |
convertColumnIndexToModel(int viewIndex)
Convert the view column index in the entire TableScrollPane to model index. |
int |
convertColumnIndexToView(int modelIndex)
Convert the view column index in the entire TableScrollPane to model index. |
protected TableModel |
createSortableTableModel(MultiTableModel tableModel,
boolean sortable)
Creates a SortableTableModel or SortableTreeTableModel for the MultiTableModel if isSortable() is true. |
protected JTable |
createTable(TableModel model,
boolean sortable)
Creates the table. |
protected JTable |
createTable(TableModel model,
boolean sortable,
int type)
Creates the table. |
protected JTable |
createTable(TableModel model,
boolean sortable,
int type,
boolean columnFooter,
int tableIndex)
Creates the table. |
protected JTable |
createTable(TableModel model,
boolean sortable,
int type,
int tableIndex)
Deprecated. We added a footer parameter to the createTable method. This method was left here for backward compatible reason. Please change your code to override createTable(javax.swing.table.TableModel,
boolean, int) instead. |
protected void |
customizeTable(JTable table)
Customizes the table created by TableScrollPane. |
JTable[] |
getAllChildTables()
Gets all child tables in an array. |
TableCellEditor |
getCellEditor()
|
boolean |
getCellSelectionEnabled()
Returns true if both row and column selection models are enabled. |
Class<?> |
getColumnClass(int column)
Returns the type of the column appearing in the view at column position column . |
int |
getColumnCount()
Gets the total column count of TableScrollPane. |
JTable |
getColumnFooterTable()
The column footer table. |
JTable |
getColumnHeaderTable()
|
String |
getColumnName(int column)
Returns the name of the column appearing in the view at column position column . |
boolean |
getColumnSelectionAllowed()
Returns true if columns can be selected. |
JTable |
getEditingTable()
|
MultiTableModel |
getFooterTableModel()
|
JTable |
getMainTable()
The main table. |
MultiTableModel |
getModel()
Gets the original table model that is passed in constructors. |
Printable |
getPrintable(JTable.PrintMode printMode,
MessageFormat headerFormat,
MessageFormat footerFormat)
Return a Printable for use in printing this JTable. |
int |
getRowCount()
Gets the total row count of TableScrollPane. |
JTable |
getRowFooterColumnFooterTable()
Gets the row footer of the column footer table. |
JTable |
getRowFooterColumnHeaderTable()
|
JTable |
getRowFooterTable()
The row footer table. |
JTable |
getRowHeaderColumnFooterTable()
Gets the row header of the column footer table. |
JTable |
getRowHeaderColumnHeaderTable()
|
JTable |
getRowHeaderTable()
The row header table. |
boolean |
getRowSelectionAllowed()
Returns true if rows can be selected. |
int |
getSelectedColumn()
Returns the index of the first selected column, -1 if no column is selected. |
int |
getSelectedColumnCount()
Returns the number of selected columns. |
int[] |
getSelectedColumns()
Returns the indices of all selected columns. |
int |
getSelectedRow()
Returns the index of the first selected row, -1 if no row is selected. |
int |
getSelectedRowCount()
Returns the number of selected rows. |
int[] |
getSelectedRows()
Returns the indices of all selected rows. |
TableScrollPane.TablePosition |
getTableAtCell(int row,
int column)
Gets the table as the specified row and column index. |
TableScrollPane.TablePosition |
getTableAtColumn(int column)
Gets the table as the specified column index. |
TableScrollPane.TablePosition |
getTableAtRow(int row)
Gets the table as the specified row index. |
TableCustomizer |
getTableCustomizer()
Gets the table customizer. |
MultiTableModel |
getTableModel()
Gets the original table model that is passed in constructors. |
Object |
getValueAt(int row,
int column)
Returns the cell value at row and column . |
boolean |
isAllowMultiSelectionInDifferentTable()
Get the flag indicating if the TableScrollPane allow select multiple rows in different tables, including main table and column footer table for example. |
boolean |
isCellEditable(int row,
int column)
Returns true if the cell at row and column is editable. |
boolean |
isCellSelected(int row,
int column)
Returns true if the specified indices are in the valid range of rows and columns and the cell at the specified position is selected. |
boolean |
isColumnSelected(int column)
Returns true if the specified index is in the valid range of columns, and the column at that index is selected. |
boolean |
isEditing()
|
boolean |
isNonContiguousCellSelectionAllowed()
Returns true if non-contiguous cell selection can be selected. |
boolean |
isRowSelected(int row)
Returns true if the specified index is in the valid range of rows, and the row at that index is selected. |
boolean |
isSortable()
|
boolean |
print()
A convenience method that displays a printing dialog, and then prints this JTable in mode
PrintMode.FIT_WIDTH , with no header or footer text. |
boolean |
print(JTable.PrintMode printMode)
A convenience method that displays a printing dialog, and then prints this JTable in the given
printing mode, with no header or footer text. |
boolean |
print(JTable.PrintMode printMode,
MessageFormat headerFormat,
MessageFormat footerFormat)
A convenience method that displays a printing dialog, and then prints this JTable in the given
printing mode, with the specified header and footer text. |
boolean |
print(JTable.PrintMode printMode,
MessageFormat headerFormat,
MessageFormat footerFormat,
boolean showPrintDialog,
PrintRequestAttributeSet attr,
boolean interactive)
Prints this table with the default printer specified as the print service. |
boolean |
print(JTable.PrintMode printMode,
MessageFormat headerFormat,
MessageFormat footerFormat,
boolean showPrintDialog,
PrintRequestAttributeSet attr,
boolean interactive,
PrintService service)
Prints this JTable . |
void |
refreshColumns()
Calls this method when getColumnType value changed in MultiTableModel. |
protected void |
removeExtraColumns(JTable table,
int type,
int tableIndex)
Removes extra columns from TableColumnModel that doesn't match with the type and tableIndex. |
void |
resizeRowHeaderTableToFit()
Resizes the row header table to fix the gap between the main table, if any. |
protected void |
resynchronizeTablesSelection()
|
void |
setAllowMultiSelectionInDifferentTable(boolean allowMultiSelectionInDifferentTable)
Set the flag indicating if the TableScrollPane allow select multiple rows in different tables, including main table and column footer table for example. |
void |
setCellSelectionEnabled(boolean cellSelectionEnabled)
Sets whether this table allows both a column selection and a row selection to exist simultaneously. |
void |
setColumnSelectionAllowed(boolean columnSelectionAllowed)
Sets whether the columns in this model can be selected. |
void |
setFooterTableModel(MultiTableModel footerTableModel)
Sets the footer table model. |
void |
setHeaderTableModel(MultiTableModel headerTableModel)
Sets the header table model. |
void |
setNonContiguousCellSelectionAllowed(boolean nonContiguousCellSelectionAllowed)
Sets whether non-contiguous cell selection in this model can be selected. |
void |
setRowSelectionAllowed(boolean rowSelectionAllowed)
Sets whether the rows in this model can be selected. |
void |
setSortable(boolean sortable)
|
void |
setTableCustomizer(TableCustomizer tableCustomizer)
Sets the table customizer. |
void |
setTableModel(MultiTableModel tableModel)
Sets the original table model and recreates all child tables. |
void |
setValueAt(Object aValue,
int row,
int column)
Sets the value for the cell in the table model at row and column . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected MultiTableModel _originalTableModel
protected MultiTableModel _originalFooterTableModel
protected MultiTableModel _originalHeaderTableModel
protected JTable _mainTable
protected JTable _rowHeaderTable
protected JTable _rowFooterTable
protected JTable _columnFooterTable
protected JTable _rowHeaderColumnFooterTable
protected JTable _rowFooterColumnFooterTable
protected JTable _columnHeaderTable
protected JTable _rowHeaderColumnHeaderTable
protected JTable _rowFooterColumnHeaderTable
public static final String TABLE_KEY
public static final String TABLESCROLLPANE_KEY
public static final String MAIN_TABLE
public static final String ROWHEADER_TABLE
public static final String ROWFOOTER_TABLE
public static final String COLUMNFOOTER_TABLE
public static final String ROWHEADER_COLUMNFOOTER_TABLE
public static final String ROWFOOTER_COLUMNFOOTER_TABLE
public static final String COLUMNHEADER_TABLE
public static final String ROWHEADER_COLUMNHEADER_TABLE
public static final String ROWFOOTER_COLUMNHEADER_TABLE
public static final String PROPERTY_TABLE_MODEL
public static final String AUTO_UPDATE_FOOTER_TABLE_COLUMNS
protected boolean _rowSelectionAllowed
protected boolean _columnSelectionAllowed
protected boolean _nonContiguousCellSelectionAllowed
Constructor Detail |
---|
public TableScrollPane()
TableScrollPane
. You can call setTableModel(com.jidesoft.grid.MultiTableModel)
to set a non-empty table model later.
public TableScrollPane(MultiTableModel tableModel)
TableScrollPane
. The tables will not be sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create up to three
tables in TableScrollPane.public TableScrollPane(MultiTableModel tableModel, MultiTableModel footerTableModel)
TableScrollPane
with a footer table. The tables will not be sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create upto three
tables in TableScrollPane.footerTableModel
- the footer table model. It will be used to create a footer table below the main table. It
must have the same column count as the MultiTableModel's non-header and non-footer column
count.public TableScrollPane(MultiTableModel tableModel, MultiTableModel footerTableModel, boolean sortable)
TableScrollPane
with a footer table. You can specify if the tables are sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create upto three
tables in TableScrollPane.footerTableModel
- the footer table model. It will be used to create a footer table below the main table. It
must have the same column count as the MultiTableModel's non-header and non-footer column
count.sortable
- if the tables will be sortable.public TableScrollPane(MultiTableModel tableModel, MultiTableModel headerTableModel, MultiTableModel footerTableModel)
TableScrollPane
with a header table and a footer table. The tables will not be sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create up to three
tables in TableScrollPane.headerTableModel
- the header table model. It will be used to create a header table below the normal table
header. It must have the same column count as the MultiTableModel's non-header and
non-footer column count.footerTableModel
- the footer table model. It will be used to create a footer table below the main table. It
must have the same column count as the MultiTableModel's non-header and non-footer column
count.public TableScrollPane(MultiTableModel tableModel, MultiTableModel headerTableModel, MultiTableModel footerTableModel, boolean sortable)
TableScrollPane
with a header table and a footer table. You can specify if the tables are
sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create up to three
tables in TableScrollPane.headerTableModel
- the header table model. It will be used to create a header table below the normal table
header. It must have the same column count as the MultiTableModel's non-header and
non-footer column count.footerTableModel
- the footer table model. It will be used to create a footer table below the main table. It
must have the same column count as the MultiTableModel's non-header and non-footer column
count.sortable
- if the tables will be sortable.public TableScrollPane(MultiTableModel tableModel, boolean sortable)
TableScrollPane
without footer table. You can specify if the tables are sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create up to three
tables in TableScrollPane.sortable
- if the tables will be sortable.public TableScrollPane(MultiTableModel tableModel, MultiTableModel footerTableModel, boolean sortable, boolean sync)
TableScrollPane
with a footer table. You can specify if the tables are sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create upto three
tables in TableScrollPane.footerTableModel
- the footer table model. It will be used to create a footer table below the main table. It
must have the same column count as the MultiTableModel's non-header and non-footer column
count.sortable
- if the tables will be sortable.sync
- if the tables will be synced. Usually you should call with sync set to true. However if
you want to synchronize more tables which are not just in one TableScrollPane, you can
set to false first, then call TableUtils.synchronizeTables(javax.swing.JTable[])
later.public TableScrollPane(MultiTableModel tableModel, MultiTableModel headerTableModel, MultiTableModel footerTableModel, boolean sortable, boolean sync)
TableScrollPane
with a header table and a footer table. You can specify if the tables are
sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create up to three
tables in TableScrollPane.headerTableModel
- the header table model. It will be used to create a header table below the normal table
header. It must have the same column count as the MultiTableModel's non-header and
non-footer column count.footerTableModel
- the footer table model. It will be used to create a footer table below the main table. It
must have the same column count as the MultiTableModel's non-header and non-footer column
count.sortable
- if the tables will be sortable.sync
- if the tables will be synced. Usually you should call with sync set to true. However if
you want to synchronize more tables which are not just in one TableScrollPane, you can
set to false first, then call TableUtils.synchronizeTables(javax.swing.JTable[])
later.public TableScrollPane(MultiTableModel tableModel, MultiTableModel footerTableModel, boolean sortable, int tableIndex, boolean sync)
TableScrollPane
with a footer table. You can specify if the tables are sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create up to three
tables in TableScrollPane.footerTableModel
- the footer table model. It will be used to create a footer table below the main table. It
must have the same column count as the MultiTableModel's non-header and non-footer column
count.sortable
- if the tables will be sortable.tableIndex
- the table index of the TableScrollPane. This is only useful when using it inside a
TableSplitPane.sync
- if the tables will be synced. Usually you should call with sync set to true. However if
you want to synchronize more tables which are not just in one TableScrollPane, you can
set to false first, then call TableUtils.synchronizeTables(javax.swing.JTable[])
later.public TableScrollPane(MultiTableModel tableModel, MultiTableModel headerTableModel, MultiTableModel footerTableModel, boolean sortable, int tableIndex, boolean sync)
TableScrollPane
with a header table and a footer table. You can specify if the tables are
sortable.
tableModel
- the MultiTableModel. This is the main table model that will be used to create up to three
tables in TableScrollPane.headerTableModel
- the header table model. It will be used to create a header table below the normal table
header. It must have the same column count as the MultiTableModel's non-header and
non-footer column count.footerTableModel
- the footer table model. It will be used to create a footer table below the main table. It
must have the same column count as the MultiTableModel's non-header and non-footer column
count.sortable
- if the tables will be sortable.tableIndex
- the table index of the TableScrollPane. This is only useful when using it inside a
TableSplitPane.sync
- if the tables will be synced. Usually you should call with sync set to true. However if
you want to synchronize more tables which are not just in one TableScrollPane, you can
set to false first, then call TableUtils.synchronizeTables(javax.swing.JTable[])
later.Method Detail |
---|
public void setTableModel(MultiTableModel tableModel)
tableModel
- the new MultiTableModelprotected TableModel createSortableTableModel(MultiTableModel tableModel, boolean sortable)
TableModel actualTableModel;
if (tableModel instanceof TreeTableModel && sortable) {
actualTableModel = new SortableTreeTableModel(tableModel);
}
else if (!(tableModel instanceof ISortableTableModel) && sortable) {
actualTableModel = new SortableTableModel(tableModel);
}
else {
actualTableModel = tableModel;
}
return actualTableModel;
tableModel
- the MultiTableModelsortable
- true or false. If true, the tableModel should be wrapped into a SortableTableModel or
SortableTreeTableModel.
public MultiTableModel getTableModel()
getModel()
.
public MultiTableModel getModel()
getTableModel()
.
public void setFooterTableModel(MultiTableModel footerTableModel)
footerTableModel
- the footer table modelpublic void setHeaderTableModel(MultiTableModel headerTableModel)
headerTableModel
- the header table modelpublic MultiTableModel getFooterTableModel()
public boolean isSortable()
public void setSortable(boolean sortable)
protected void customizeTable(JTable table)
MAIN_TABLE
, ROWHEADER_TABLE
, ROWFOOTER_TABLE
, COLUMNFOOTER_TABLE
, ROWHEADER_COLUMNFOOTER_TABLE
,
and ROWFOOTER_COLUMNFOOTER_TABLE
.
table
- the child tablepublic JTable getMainTable()
public JTable getRowHeaderTable()
public JTable getRowFooterTable()
public JTable getColumnFooterTable()
public JTable getRowHeaderColumnFooterTable()
public JTable getRowFooterColumnFooterTable()
public JTable getColumnHeaderTable()
public JTable getRowHeaderColumnHeaderTable()
public JTable getRowFooterColumnHeaderTable()
@Deprecated protected JTable createTable(TableModel model, boolean sortable, int type, int tableIndex)
createTable(javax.swing.table.TableModel,
boolean, int)
instead.
model
- the table modelsortable
- if the table is sortabletype
- the table typetableIndex
- the table index
protected JTable createTable(TableModel model, boolean sortable, int type, boolean columnFooter, int tableIndex)
TableScrollPane
will use this method to create all table instances.
Please be noted that it is highly NOT recommended to override this method although you could do that. The reason
is that we did some client property registrations and some default setting here. So if you override this method
without taking care of that part, you will find the behavior of your new TableScrollPane is not as you are
actually expecting.
If you want to create an instance with different table class, please try override createTable(javax.swing.table.TableModel, boolean, int)
or createTable(javax.swing.table.TableModel,
boolean)
. If you will create different table classes for header table and main table, you would have to override
the first one, which has type as one of its three parameters. If you will create the same table class for every
table in your TableScrollPane, you could just override the second one with only two parameters.
If you want to configure the tables which ares already created, please override getTableCustomizer()
to
create your own table customizer. You can refer our TableScrollPaneDemo
for the details.
Below is the default client property registrations and settings in this method. If you decided to override this
one, please also consider add those lines in.
String tableKey = null;
switch (type) {
case MultiTableModel.REGULAR_COLUMN:
tableKey = columnFooter ? COLUMNFOOTER_TABLE : MAIN_TABLE;
break;
case MultiTableModel.HEADER_COLUMN:
tableKey = columnFooter ? ROWHEADER_COLUMNFOOTER_TABLE : ROWHEADER_TABLE;
break;
case MultiTableModel.FOOTER_COLUMN:
tableKey = columnFooter ? ROWFOOTER_COLUMNFOOTER_TABLE : ROWFOOTER_TABLE;
break;
}
table.putClientProperty(TABLE_KEY, tableKey);
table.putClientProperty(TableSplitPane.TABLE_INDEX, tableIndex);
table.putClientProperty(TABLESCROLLPANE_KEY, this);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
if (table instanceof SortableTable) {
((SortableTable) table).setSortable(sortable);
}
return table;
model
- the table model.sortable
- if the table is sortable.type
- the valid values are MultiTableModel.REGULAR_COLUMN
, MultiTableModel.HEADER_COLUMN
and MultiTableModel.FOOTER_COLUMN
columnFooter
- true if the table is for a column footer. Otherwise false.tableIndex
- the index of the table. THe value is returned from MultiTableModel.getTableIndex(int)
method.
protected JTable createTable(TableModel model, boolean sortable, int type)
getTableCustomizer()
.
The default implementation of this method is like below:
return createTable(model, sortable);
As you can see at that method, it will return a SortableTable by default. If you want to use another table such
as TreeTable, you can override this method and use parameters type and table Index to determine it is row header
table, then return a TreeTable instead.
model
- the table modelsortable
- true or false.type
- the valid values are MultiTableModel.REGULAR_COLUMN
, MultiTableModel.HEADER_COLUMN
and MultiTableModel.FOOTER_COLUMN
protected JTable createTable(TableModel model, boolean sortable)
createTable(javax.swing.table.TableModel, boolean,
int, boolean, int)
if you just want to configure the table with no intention to create your own table.
The default implementation is like below:
return new SortableTable(model);
As you can see, it will return a SortableTable by default.
model
- the table modelsortable
- true or false.
public boolean isEditing()
public JTable getEditingTable()
public JTable[] getAllChildTables()
public TableCellEditor getCellEditor()
protected void removeExtraColumns(JTable table, int type, int tableIndex)
table
- the tabletype
- the table type such as REGULAR_COLUMN, FOOTER_COLUMN or HEADER_COLUMN.tableIndex
- the table indexpublic void refreshColumns()
public void resizeRowHeaderTableToFit()
public TableCustomizer getTableCustomizer()
public void setTableCustomizer(TableCustomizer tableCustomizer)
tableCustomizer
- the new table customizer.public void setRowSelectionAllowed(boolean rowSelectionAllowed)
setRowSelectionAllowed
in interface TableAdapter
rowSelectionAllowed
- true if this model will allow row selectiongetRowSelectionAllowed()
public boolean getRowSelectionAllowed()
getRowSelectionAllowed
in interface TableAdapter
setRowSelectionAllowed(boolean)
public void setColumnSelectionAllowed(boolean columnSelectionAllowed)
setColumnSelectionAllowed
in interface TableAdapter
columnSelectionAllowed
- true if this model will allow column selectiongetColumnSelectionAllowed()
public boolean getColumnSelectionAllowed()
getColumnSelectionAllowed
in interface TableAdapter
setColumnSelectionAllowed(boolean)
public void setCellSelectionEnabled(boolean cellSelectionEnabled)
isCellSelected
to change this default behavior. This method is equivalent to setting both the
rowSelectionAllowed
property and columnSelectionAllowed
property of the
columnModel
to the supplied value.
setCellSelectionEnabled
in interface TableAdapter
cellSelectionEnabled
- true if simultaneous row and column selection is allowedgetCellSelectionEnabled()
public boolean getCellSelectionEnabled()
getRowSelectionAllowed() &&
getColumnSelectionAllowed()
.
getCellSelectionEnabled
in interface TableAdapter
setCellSelectionEnabled(boolean)
public void setNonContiguousCellSelectionAllowed(boolean nonContiguousCellSelectionAllowed)
nonContiguousCellSelectionAllowed
- true if this model will allow non-contiguous cell selectionisNonContiguousCellSelectionAllowed()
public boolean isNonContiguousCellSelectionAllowed()
setNonContiguousCellSelectionAllowed(boolean)
protected void resynchronizeTablesSelection()
public int getRowCount()
getRowCount
in interface TableAdapter
public int getColumnCount()
getColumnCount
in interface TableAdapter
public boolean isAllowMultiSelectionInDifferentTable()
public void setAllowMultiSelectionInDifferentTable(boolean allowMultiSelectionInDifferentTable)
allowMultiSelectionInDifferentTable
- true if allow multiple selection. Otherwise false.public TableScrollPane.TablePosition getTableAtColumn(int column)
column
- the column index related to TableScrollPane.
public TableScrollPane.TablePosition getTableAtRow(int row)
row
- the row index related to TableScrollPane.
public TableScrollPane.TablePosition getTableAtCell(int row, int column)
row
- the row index related to TableScrollPane.column
- the column index related to TableScrollPane.
public String getColumnName(int column)
column
.
getColumnName
in interface TableAdapter
column
- the column in the view being queried
column
in the view where the first column is column 0public Class<?> getColumnClass(int column)
column
.
getColumnClass
in interface TableAdapter
column
- the column in the view being queried
column
in the view where the first column is column 0public 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 interface TableAdapter
row
- the row whose value is to be queriedcolumn
- the column whose value is to be queried
public void setValueAt(Object aValue, 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.
aValue
is the new value.
setValueAt
in interface TableAdapter
aValue
- the new valuerow
- the row of the cell to be changedcolumn
- the column of the cell to be changedgetValueAt(int, int)
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 interface TableAdapter
row
- the row whose value is to be queriedcolumn
- the column whose value is to be queried
setValueAt(Object, int, int)
public int getSelectedRow()
getSelectedRow
in interface TableAdapter
public int getSelectedColumn()
getSelectedColumn
in interface TableAdapter
public int[] getSelectedRows()
getSelectedRows
in interface TableAdapter
getSelectedRow()
public int convertColumnIndexToView(int modelIndex)
modelIndex
- the model column index
public int convertColumnIndexToModel(int viewIndex)
viewIndex
- the view column index counting from 0 including row header table, main table and row footer
table
public int[] getSelectedColumns()
getSelectedColumns
in interface TableAdapter
getSelectedColumn()
public int getSelectedRowCount()
getSelectedRowCount
in interface TableAdapter
public int getSelectedColumnCount()
getSelectedColumnCount
in interface TableAdapter
public boolean isRowSelected(int row)
isRowSelected
in interface TableAdapter
row
- the row index
row
is a valid index and the row at that index is selected (where 0 is the first
row)public boolean isColumnSelected(int column)
isColumnSelected
in interface TableAdapter
column
- the column in the column model
column
is a valid index and the column at that index is selected (where 0 is the
first column)public boolean isCellSelected(int row, int column)
isCellSelected
in interface TableAdapter
row
- the row being queriedcolumn
- the column being queried
row
and column
are valid indices and the cell at index (row,
column)
is selected, where the first row and first column are at index 0public void clearSelection()
public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
TableAdapter
toggle
and
extend
. Most changes to the selection that are the result of keyboard or mouse events received by
the UI are channeled through this method so that the behavior may be overridden by a subclass. Some UIs may need
more functionality than this method provides, such as when manipulating the lead for discontiguous selection, and
may not call into this method for some selection changes.
This implementation uses the following conventions: toggle
: false,
extend
: false. Clear the previous selection and ensure the new cell is selected. toggle
: false, extend
: true. Extend the previous selection from the
anchor to the specified cell, clearing all other selections. toggle
: true,
extend
: false. If the specified cell is selected, deselect it. If it is not selected,
select it. toggle
: true, extend
: true. Apply the selection state
of the anchor to all cells between it and the specified cell.
changeSelection
in interface TableAdapter
rowIndex
- affects the selection at row
columnIndex
- affects the selection at column
toggle
- see description aboveextend
- if true, extend the current selectionpublic boolean print() throws PrinterException
JTable
in mode
PrintMode.FIT_WIDTH
, with no header or footer text. A modal progress dialog, with an abort option,
will be shown for the duration of printing.
Note: In headless mode, no dialogs are shown and printing occurs on the default printer.
SecurityException
- if this thread is not allowed to initiate a print job request
PrinterException
- if an error in the print system causes the job to be abortedprint(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat, boolean,
javax.print.attribute.PrintRequestAttributeSet, boolean, javax.print.PrintService)
,
getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)
public boolean print(JTable.PrintMode printMode) throws PrinterException
JTable
in the given
printing mode, with no header or footer text. A modal progress dialog, with an abort option, will be shown for
the duration of printing.
Note: In headless mode, no dialogs are shown and printing occurs on the default printer.
printMode
- the printing mode that the printable should use
SecurityException
- if this thread is not allowed to initiate a print job request
PrinterException
- if an error in the print system causes the job to be abortedprint(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat, boolean,
javax.print.attribute.PrintRequestAttributeSet, boolean, javax.print.PrintService)
,
getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)
public boolean print(JTable.PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat) throws PrinterException
JTable
in the given
printing mode, with the specified header and footer text. A modal progress dialog, with an abort option, will be
shown for the duration of printing.
Note: In headless mode, no dialogs are shown and printing occurs on the default printer.
printMode
- the printing mode that the printable should useheaderFormat
- a MessageFormat
specifying the text to be used in printing a header, or null for
nonefooterFormat
- a MessageFormat
specifying the text to be used in printing a footer, or null for
none
SecurityException
- if this thread is not allowed to initiate a print job request
PrinterException
- if an error in the print system causes the job to be abortedprint(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat, boolean,
javax.print.attribute.PrintRequestAttributeSet, boolean, javax.print.PrintService)
,
getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)
public boolean print(JTable.PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat, boolean showPrintDialog, PrintRequestAttributeSet attr, boolean interactive) throws PrinterException, HeadlessException
printMode
- the printing mode that the printable should useheaderFormat
- a MessageFormat
specifying the text to be used in printing a header, or
null
for nonefooterFormat
- a MessageFormat
specifying the text to be used in printing a footer, or
null
for noneshowPrintDialog
- whether or not to display a print dialogattr
- a PrintRequestAttributeSet
specifying any printing attributes, or
null
for noneinteractive
- whether or not to print in an interactive mode
HeadlessException
- if the method is asked to show a printing dialog or run interactively, and
GraphicsEnvironment.isHeadless
returns true
SecurityException
- if this thread is not allowed to initiate a print job request
PrinterException
- if an error in the print system causes the job to be abortedprint(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat, boolean,
javax.print.attribute.PrintRequestAttributeSet, boolean, javax.print.PrintService)
,
getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)
public boolean print(JTable.PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat, boolean showPrintDialog, PrintRequestAttributeSet attr, boolean interactive, PrintService service) throws PrinterException, HeadlessException
JTable
. Takes steps that the majority of developers would take in order to print a
JTable
. In short, it prepares the table, calls getPrintable
to fetch an appropriate
Printable
, and then sends it to the printer.
A boolean
parameter allows you to specify whether or not a printing dialog is displayed to the user.
When it is, the user may use the dialog to change the destination printer or printing attributes, or even to
cancel the print. Another two parameters allow for a PrintService
and printing attributes to be
specified. These parameters can be used either to provide initial values for the print dialog, or to specify
values when the dialog is not shown.
A second boolean
parameter allows you to specify whether or not to perform printing in an
interactive mode. If true
, a modal progress dialog, with an abort option, is displayed for the
duration of printing . This dialog also prevents any user action which may affect the table. However, it can not
prevent the table from being modified by code (for example, another thread that posts updates using
SwingUtilities.invokeLater
). It is therefore the responsibility of the developer to ensure that no
other code modifies the table in any way during printing (invalid modifications include changes in: size,
renderers, or underlying data). Printing behavior is undefined when the table is changed during printing.
If false
is specified for this parameter, no dialog will be displayed and printing will begin
immediately on the event-dispatch thread. This blocks any other events, including repaints, from being processed
until printing is complete. Although this effectively prevents the table from being changed, it doesn't provide a
good user experience. For this reason, specifying false
is only recommended when printing from an
application with no visible GUI.
Note: Attempting to show the printing dialog or run interactively, while in headless mode, will result in a
HeadlessException
.
Before fetching the printable, this method will gracefully terminate editing, if necessary, to prevent an editor
from showing in the printed result. Additionally, JTable
will prepare its renderers during printing
such that selection and focus are not indicated. As far as customizing further how the table looks in the
printout, developers can provide custom renderers or paint code that conditionalize on the value of JComponent.isPaintingForPrint()
.
See getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)
for more description on how the table is printed.
printMode
- the printing mode that the printable should useheaderFormat
- a MessageFormat
specifying the text to be used in printing a header, or
null
for nonefooterFormat
- a MessageFormat
specifying the text to be used in printing a footer, or
null
for noneshowPrintDialog
- whether or not to display a print dialogattr
- a PrintRequestAttributeSet
specifying any printing attributes, or
null
for noneinteractive
- whether or not to print in an interactive modeservice
- the destination PrintService
, or null
to use the default
printer
HeadlessException
- if the method is asked to show a printing dialog or run interactively, and
GraphicsEnvironment.isHeadless
returns true
SecurityException
- if a security manager exists and its SecurityManager.checkPrintJobAccess()
method disallows this thread from creating a print job request
PrinterException
- if an error in the print system causes the job to be abortedgetPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)
public Printable getPrintable(JTable.PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat)
Printable
for use in printing this JTable.
This method is meant for those wishing to customize the default Printable
implementation used by
JTable
's print
methods. Developers wanting simply to print the table should use one of
those methods directly.
The Printable
can be requested in one of two printing modes. In both modes, it spreads table rows
naturally in sequence across multiple pages, fitting as many rows as possible per page.
PrintMode.NORMAL
specifies that the table be printed at its current size. In this mode, there may be
a need to spread columns across pages in a similar manner to that of the rows. When the need arises, columns are
distributed in an order consistent with the table's ComponentOrientation
.
PrintMode.FIT_WIDTH
specifies that the output be scaled smaller, if necessary, to fit the table's
entire width (and thereby all columns) on each page. Width and height are scaled equally, maintaining the aspect
ratio of the output.
The Printable
heads the portion of table on each page with the appropriate section from the table's
JTableHeader
, if it has one.
Header and footer text can be added to the output by providing MessageFormat
arguments. The printing
code requests Strings from the formats, providing a single item which may be included in the formatted string: an
Integer
representing the current page number.
You are encouraged to read the documentation for MessageFormat
as some characters, such as
single-quote, are special and need to be escaped.
Here's an example of creating a MessageFormat
that can be used to print "Duke's Table: Page - " and
the current page number:
// notice the escaping of the single quote // notice how the page number is included with "{0}" MessageFormat format = new MessageFormat("Duke''s Table: Page - {0}");The
Printable
constrains what it draws to the printable area of each page that it prints. Under
certain circumstances, it may find it impossible to fit all of a page's content into that area. In these cases
the output may be clipped, but the implementation makes an effort to do something reasonable. Here are a few
situations where this is known to occur, and how they may be handled by this particular implementation: ComponentOrientation
. PrintMode.NORMAL
when a column is too wide to fit in the printable area -- print the center portion of the column and leave the
left and right borders off the table. Printable
to be wrapped inside another in order to create complex
reports and documents. You may even request that different pages be rendered into different sized printable
areas. The implementation must be prepared to handle this (possibly by doing its layout calculations on the fly).
However, providing different heights to each page will likely not work well with PrintMode.NORMAL
when it has to spread columns across pages.
As far as customizing how the table looks in the printed result, JTable
itself will take care of
hiding the selection and focus during printing. For additional customizations, your renderers or painting code
can customize the look based on the value of JComponent.isPaintingForPrint()
Also, before calling this method you may wish to first modify the state of the table, such as to
cancel cell editing or have the user size the table appropriately. However, you must not modify the state of the
table after this Printable
has been fetched (invalid modifications include changes in size or
underlying data). The behavior of the returned Printable
is undefined once the table has been
changed.
printMode
- the printing mode that the printable should useheaderFormat
- a MessageFormat
specifying the text to be used in printing a header, or null for
nonefooterFormat
- a MessageFormat
specifying the text to be used in printing a footer, or null for
none
Printable
for printing this JTableprint(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat, boolean,
javax.print.attribute.PrintRequestAttributeSet, boolean, javax.print.PrintService)
,
Printable
,
PrinterJob
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |