JTable (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[ImageObserver](../../java/awt/image/ImageObserver.html "interface in java.awt.image")
, [MenuContainer](../../java/awt/MenuContainer.html "interface in java.awt")
, [Serializable](../../../java.base/java/io/Serializable.html "interface in java.io")
, [EventListener](../../../java.base/java/util/EventListener.html "interface in java.util")
, [Accessible](../accessibility/Accessible.html "interface in javax.accessibility")
, [CellEditorListener](event/CellEditorListener.html "interface in javax.swing.event")
, [ListSelectionListener](event/ListSelectionListener.html "interface in javax.swing.event")
, [RowSorterListener](event/RowSorterListener.html "interface in javax.swing.event")
, [TableColumnModelListener](event/TableColumnModelListener.html "interface in javax.swing.event")
, [TableModelListener](event/TableModelListener.html "interface in javax.swing.event")
, [Scrollable](Scrollable.html "interface in javax.swing")
@JavaBean(defaultProperty="UI", description="A component which displays data in a two dimensional grid.") public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible, RowSorterListener
The JTable
is used to display and edit regular two-dimensional tables of cells. See How to Use Tables in The Java Tutorial for task-oriented documentation and examples of using JTable
.
The JTable
has many facilities that make it possible to customize its rendering and editing but provides defaults for these features so that simple tables can be set up easily. For example, to set up a table with 10 rows and 10 columns of numbers:
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return 10; }
public int getRowCount() { return 10;}
public Object getValueAt(int row, int col) { return Integer.valueOf(row*col); }
};
JTable table = new JTable(dataModel);
JScrollPane scrollpane = new JScrollPane(table);
JTable
s are typically placed inside of a JScrollPane
. By default, a JTable
will adjust its width such that a horizontal scrollbar is unnecessary. To allow for a horizontal scrollbar, invoke setAutoResizeMode(int) with AUTO_RESIZE_OFF
. Note that if you wish to use a JTable
in a standalone view (outside of a JScrollPane
) and want the header displayed, you can get it using getTableHeader() and display it separately.
To enable sorting and filtering of rows, use aRowSorter
. You can set up a row sorter in either of two ways:
- Directly set the
RowSorter
. For example:table.setRowSorter(new TableRowSorter(model))
. - Set the
autoCreateRowSorter
property totrue
, so that theJTable
creates aRowSorter
for you. For example:setAutoCreateRowSorter(true)
.
When designing applications that use the JTable
it is worth paying close attention to the data structures that will represent the table's data. The DefaultTableModel
is a model implementation that uses a Vector
of Vector
s of Object
s to store the cell values. As well as copying the data from an application into the DefaultTableModel
, it is also possible to wrap the data in the methods of theTableModel
interface so that the data can be passed to theJTable
directly, as in the example above. This often results in more efficient applications because the model is free to choose the internal representation that best suits the data. A good rule of thumb for deciding whether to use the AbstractTableModel
or the DefaultTableModel
is to use the AbstractTableModel
as the base class for creating subclasses and the DefaultTableModel
when subclassing is not required.
The "TableExample" directory in the demo area of the source distribution gives a number of complete examples of JTable
usage, covering how the JTable
can be used to provide an editable view of data taken from a database and how to modify the columns in the display to use specialized renderers and editors.
The JTable
uses integers exclusively to refer to both the rows and the columns of the model that it displays. The JTable
simply takes a tabular range of cells and uses getValueAt(int, int)
to retrieve the values from the model during painting. It is important to remember that the column and row indexes returned by various JTable
methods are in terms of the JTable
(the view) and are not necessarily the same indexes used by the model.
By default, columns may be rearranged in the JTable
so that the view's columns appear in a different order to the columns in the model. This does not affect the implementation of the model at all: when the columns are reordered, the JTable
maintains the new order of the columns internally and converts its column indices before querying the model.
So, when writing a TableModel
, it is not necessary to listen for column reordering events as the model will be queried in its own coordinate system regardless of what is happening in the view. In the examples area there is a demonstration of a sorting algorithm making use of exactly this technique to interpose yet another coordinate system where the order of the rows is changed, rather than the order of the columns.
Similarly when using the sorting and filtering functionality provided by RowSorter
the underlyingTableModel
does not need to know how to do sorting, rather RowSorter
will handle it. Coordinate conversions will be necessary when using the row based methods ofJTable
with the underlying TableModel
. All of JTable
s row based methods are in terms of theRowSorter
, which is not necessarily the same as that of the underlying TableModel
. For example, the selection is always in terms of JTable
so that when using RowSorter
you will need to convert usingconvertRowIndexToView
orconvertRowIndexToModel
. The following shows how to convert coordinates from JTable
to that of the underlying model:
int[] selection = table.getSelectedRows(); for (int i = 0; i < selection.length; i++) { selection[i] = table.convertRowIndexToModel(selection[i]); } // selection is now in terms of the underlying TableModel
By default if sorting is enabled JTable
will persist the selection and variable row heights in terms of the model on sorting. For example if row 0, in terms of the underlying model, is currently selected, after the sort row 0, in terms of the underlying model will be selected. Visually the selection may change, but in terms of the underlying model it will remain the same. The one exception to that is if the model index is no longer visible or was removed. For example, if row 0 in terms of model was filtered out the selection will be empty after the sort.
J2SE 5 adds methods to JTable
to provide convenient access to some common printing needs. Simple new print() methods allow for quick and easy addition of printing support to your application. In addition, a newgetPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat) method is available for more advanced printing needs.
As for all JComponent
classes, you can useInputMap and ActionMap to associate anAction object with a KeyStroke and execute the action under specified conditions.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans
package. Please see XMLEncoder.
Since:
1.2
See Also:
DefaultTableModel, TableRowSorter
Nested Class Summary
Nested Classes
Modifier and Type | Class | Description |
---|---|---|
protected class | JTable.AccessibleJTable | This class implements accessibility support for theJTable class. |
static class | JTable.DropLocation | A subclass of TransferHandler.DropLocation representing a drop location for a JTable. |
static class | JTable.PrintMode | Printing modes, used in printing JTables. |
Field Summary
Fields
Modifier and Type | Field | Description |
---|---|---|
static int | AUTO_RESIZE_ALL_COLUMNS | During all resize operations, proportionately resize all columns. |
static int | AUTO_RESIZE_LAST_COLUMN | During all resize operations, apply adjustments to the last column only. |
static int | AUTO_RESIZE_NEXT_COLUMN | When a column is adjusted in the UI, adjust the next column the opposite way. |
static int | AUTO_RESIZE_OFF | Do not adjust column widths automatically; use a horizontal scrollbar instead. |
static int | AUTO_RESIZE_SUBSEQUENT_COLUMNS | During UI adjustment, change subsequent columns to preserve the total width; this is the default behavior. |
protected boolean | autoCreateColumnsFromModel | The table will query the TableModel to build the default set of columns if this is true. |
protected int | autoResizeMode | Determines if the table automatically resizes the width of the table's columns to take up the entire width of the table, and how it does the resizing. |
protected TableCellEditor | cellEditor | The active cell editor object, that overwrites the screen real estate occupied by the current cell and allows the user to change its contents. |
protected boolean | cellSelectionEnabled | Obsolete as of Java 2 platform v1.3. |
protected TableColumnModel | columnModel | The TableColumnModel of the table. |
protected TableModel | dataModel | The TableModel of the table. |
protected Hashtable<Object,Object> | defaultEditorsByColumnClass | A table of objects that display and edit the contents of a cell, indexed by class as declared in getColumnClass in the TableModel interface. |
protected Hashtable<Object,Object> | defaultRenderersByColumnClass | A table of objects that display the contents of a cell, indexed by class as declared in getColumnClass in the TableModel interface. |
protected int | editingColumn | Identifies the column of the cell being edited. |
protected int | editingRow | Identifies the row of the cell being edited. |
protected Component | editorComp | If editing, the Component that is handling the editing. |
protected Color | gridColor | The color of the grid. |
protected Dimension | preferredViewportSize | Used by the Scrollable interface to determine the initial visible area. |
protected int | rowHeight | The height in pixels of each row in the table. |
protected int | rowMargin | The height in pixels of the margin between the cells in each row. |
protected boolean | rowSelectionAllowed | True if row selection is allowed in this table. |
protected Color | selectionBackground | The background color of selected cells. |
protected Color | selectionForeground | The foreground color of selected cells. |
protected ListSelectionModel | selectionModel | The ListSelectionModel of the table, used to keep track of row selections. |
protected boolean | showHorizontalLines | The table draws horizontal lines between cells if showHorizontalLines is true. |
protected boolean | showVerticalLines | The table draws vertical lines between cells if showVerticalLines is true. |
protected JTableHeader | tableHeader | The TableHeader working with the table. |
Constructor Summary
Constructors
Constructor | Description |
---|---|
JTable() | Constructs a default JTable that is initialized with a default data model, a default column model, and a default selection model. |
JTable(int numRows, int numColumns) | Constructs a JTable with numRows and numColumns of empty cells usingDefaultTableModel. |
JTable(Object[][] rowData,Object[] columnNames) | Constructs a JTable to display the values in the two dimensional array,rowData, with column names, columnNames. |
JTable(Vector rowData,[Vector](../../../java.base/java/util/Vector.html "class in java.util") columnNames) | Constructs a JTable to display the values in theVector of Vectors, rowData, with column names, columnNames. |
JTable(TableModel dm) | Constructs a JTable that is initialized withdm as the data model, a default column model, and a default selection model. |
JTable(TableModel dm,TableColumnModel cm) | Constructs a JTable that is initialized withdm as the data model, cm as the column model, and a default selection model. |
JTable(TableModel dm,TableColumnModel cm,ListSelectionModel sm) | Constructs a JTable that is initialized withdm as the data model, cm as the column model, and sm as the selection model. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void | addColumn(TableColumn aColumn) | Appends aColumn to the end of the array of columns held by this JTable's column model. |
void | addColumnSelectionInterval(int index0, int index1) | Adds the columns from index0 to index1, inclusive, to the current selection. |
void | addNotify() | Calls the configureEnclosingScrollPane method. |
void | addRowSelectionInterval(int index0, int index1) | Adds the rows from index0 to index1, inclusive, to the current selection. |
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. |
void | columnAdded(TableColumnModelEvent e) | Invoked when a column is added to the table column model. |
int | columnAtPoint(Point point) | Returns the index of the column that point lies in, or -1 if the result is not in the range [0, getColumnCount()-1]. |
void | columnMarginChanged(ChangeEvent e) | Invoked when a column is moved due to a margin change. |
void | columnMoved(TableColumnModelEvent e) | Invoked when a column is repositioned. |
void | columnRemoved(TableColumnModelEvent e) | Invoked when a column is removed from the table column model. |
void | columnSelectionChanged(ListSelectionEvent e) | Invoked when the selection model of the TableColumnModel is changed. |
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. |
int | convertColumnIndexToModel(int viewColumnIndex) | Maps the index of the column in the view atviewColumnIndex to the index of the column in the table model. |
int | convertColumnIndexToView(int modelColumnIndex) | Maps the index of the column in the table model atmodelColumnIndex to the index of the column in the view. |
int | convertRowIndexToModel(int viewRowIndex) | Maps the index of the row in terms of the view to the underlying TableModel. |
int | convertRowIndexToView(int modelRowIndex) | Maps the index of the row in terms of theTableModel to the view. |
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 TableModel | createDefaultDataModel() | Returns the default table model object, which is a DefaultTableModel. |
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 ListSelectionModel | createDefaultSelectionModel() | Returns the default selection model object, which is a DefaultListSelectionModel. |
protected JTableHeader | createDefaultTableHeader() | Returns the default table header object, which is a JTableHeader. |
static JScrollPane | createScrollPaneForTable(JTable aTable) | Deprecated. |
void | doLayout() | Causes this table to lay out its rows and columns. |
boolean | editCellAt(int row, int column) | Programmatically starts editing the cell at row andcolumn, if those indices are in the valid range, and the cell at those indices is editable. |
boolean | editCellAt(int row, int column,EventObject e) | Programmatically starts editing the cell at row andcolumn, if those indices are in the valid range, and the cell at those indices is editable. |
void | editingCanceled(ChangeEvent e) | Invoked when editing is canceled. |
void | editingStopped(ChangeEvent e) | Invoked when editing is finished. |
AccessibleContext | getAccessibleContext() | Gets the AccessibleContext associated with this JTable. |
boolean | getAutoCreateColumnsFromModel() | Determines whether the table will create default columns from the model. |
boolean | getAutoCreateRowSorter() | Returns true if whenever the model changes, a newRowSorter should be created and installed as the table's sorter; otherwise, returns false. |
int | getAutoResizeMode() | Returns the auto resize mode of the table. |
TableCellEditor | getCellEditor() | Returns the active cell editor, which is null if the table is not currently editing. |
TableCellEditor | getCellEditor(int row, int column) | Returns an appropriate editor for the cell specified byrow and column. |
Rectangle | getCellRect(int row, int column, boolean includeSpacing) | Returns a rectangle for the cell that lies at the intersection ofrow and column. |
TableCellRenderer | getCellRenderer(int row, int column) | Returns an appropriate renderer for the cell specified by this row and column. |
boolean | getCellSelectionEnabled() | Returns true if both row and column selection models are enabled. |
TableColumn | getColumn(Object identifier) | Returns the TableColumn object for the column in the table whose identifier is equal to identifier, when compared usingequals. |
Class<?> | getColumnClass(int column) | Returns the type of the column appearing in the view at column position column. |
int | getColumnCount() | Returns the number of columns in the column model. |
TableColumnModel | getColumnModel() | Returns the TableColumnModel that contains all column information of this table. |
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. |
TableCellEditor | getDefaultEditor(Class<?> columnClass) | Returns the editor to be used when no editor has been set in a TableColumn. |
TableCellRenderer | getDefaultRenderer(Class<?> columnClass) | Returns the cell renderer to be used when no renderer has been set in a TableColumn. |
boolean | getDragEnabled() | Returns whether or not automatic drag handling is enabled. |
JTable.DropLocation | getDropLocation() | Returns the location that this component should visually indicate as the drop location during a DnD operation over the component, or null if no location is to currently be shown. |
DropMode | getDropMode() | Returns the drop mode for this component. |
int | getEditingColumn() | Returns the index of the column that contains the cell currently being edited. |
int | getEditingRow() | Returns the index of the row that contains the cell currently being edited. |
Component | getEditorComponent() | Returns the component that is handling the editing session. |
boolean | getFillsViewportHeight() | Returns whether or not this table is always made large enough to fill the height of an enclosing viewport. |
Color | getGridColor() | Returns the color used to draw grid lines. |
Dimension | getIntercellSpacing() | Returns the horizontal and vertical space between cells. |
TableModel | getModel() | Returns the TableModel that provides the data displayed by thisJTable. |
Dimension | getPreferredScrollableViewportSize() | Returns the preferred size of the viewport for this table. |
Printable | getPrintable(JTable.PrintMode printMode,MessageFormat headerFormat,MessageFormat footerFormat) | Return a Printable for use in printing this JTable. |
int | getRowCount() | Returns the number of rows that can be shown in theJTable, given unlimited space. |
int | getRowHeight() | Returns the height of a table row, in pixels. |
int | getRowHeight(int row) | Returns the height, in pixels, of the cells in row. |
int | getRowMargin() | Gets the amount of empty space, in pixels, between cells. |
boolean | getRowSelectionAllowed() | Returns true if rows can be selected. |
RowSorter<? extends TableModel> | getRowSorter() | Returns the object responsible for sorting. |
int | getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) | Returns visibleRect.height orvisibleRect.width, depending on this table's orientation. |
boolean | getScrollableTracksViewportHeight() | Returns false to indicate that the height of the viewport does not determine the height of the table, unlessgetFillsViewportHeight is true and the preferred height of the table is smaller than the viewport's height. |
boolean | getScrollableTracksViewportWidth() | Returns false if autoResizeMode is set toAUTO_RESIZE_OFF, which indicates that the width of the viewport does not determine the width of the table. |
int | getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) | Returns the scroll increment (in pixels) that completely exposes one new row or column (depending on the orientation). |
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. |
Color | getSelectionBackground() | Returns the background color for selected cells. |
Color | getSelectionForeground() | Returns the foreground color for selected cells. |
ListSelectionModel | getSelectionModel() | Returns the ListSelectionModel that is used to maintain row selection state. |
boolean | getShowHorizontalLines() | Returns true if the table draws horizontal lines between cells, false if it doesn't. |
boolean | getShowVerticalLines() | Returns true if the table draws vertical lines between cells, false if it doesn't. |
boolean | getSurrendersFocusOnKeystroke() | Returns true if the editor should get the focus when keystrokes cause the editor to be activated |
JTableHeader | getTableHeader() | Returns the tableHeader used by this JTable. |
String | getToolTipText(MouseEvent event) | Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set. |
TableUI | getUI() | Returns the L&F object that renders this component. |
String | getUIClassID() | Returns the suffix used to construct the name of the L&F class used to render this component. |
boolean | getUpdateSelectionOnSort() | Returns true if the selection should be updated after sorting. |
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 | 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() | Returns true if a cell is being edited. |
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. |
void | moveColumn(int column, int targetColumn) | Moves the column column to the position currently occupied by the column targetColumn in the view. |
protected String | paramString() | Returns a string representation of this table. |
Component | prepareEditor(TableCellEditor editor, int row, int column) | Prepares the editor by querying the data model for the value and selection state of the cell at row, column. |
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. |
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, as specified by the fully featuredprint method, 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 | removeColumn(TableColumn aColumn) | Removes aColumn from this JTable's array of columns. |
void | removeColumnSelectionInterval(int index0, int index1) | Deselects the columns from index0 to index1, inclusive. |
void | removeEditor() | Discards the editor object and frees the real estate it used for cell rendering. |
void | removeNotify() | Calls the unconfigureEnclosingScrollPane method. |
void | removeRowSelectionInterval(int index0, int index1) | Deselects the rows from index0 to index1, inclusive. |
protected void | resizeAndRepaint() | Equivalent to revalidate followed by repaint. |
int | rowAtPoint(Point point) | Returns the index of the row that point lies in, or -1 if the result is not in the range [0, getRowCount()-1]. |
void | selectAll() | Selects all rows, columns, and cells in the table. |
void | setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel) | Sets this table's autoCreateColumnsFromModel flag. |
void | setAutoCreateRowSorter(boolean autoCreateRowSorter) | Specifies whether a RowSorter should be created for the table whenever its model changes. |
void | setAutoResizeMode(int mode) | Sets the table's auto resize mode when the table is resized. |
void | setCellEditor(TableCellEditor anEditor) | Sets the active cell editor. |
void | setCellSelectionEnabled(boolean cellSelectionEnabled) | Sets whether this table allows both a column selection and a row selection to exist simultaneously. |
void | setColumnModel(TableColumnModel columnModel) | Sets the column model for this table to columnModel and registers for listener notifications from the new column model. |
void | setColumnSelectionAllowed(boolean columnSelectionAllowed) | Sets whether the columns in this model can be selected. |
void | setColumnSelectionInterval(int index0, int index1) | Selects the columns from index0 to index1, inclusive. |
void | setDefaultEditor(Class<?> columnClass,TableCellEditor editor) | Sets a default cell editor to be used if no editor has been set in a TableColumn. |
void | setDefaultRenderer(Class<?> columnClass,TableCellRenderer renderer) | Sets a default cell renderer to be used if no renderer has been set in a TableColumn. |
void | setDragEnabled(boolean b) | Turns on or off automatic drag handling. |
void | setDropMode(DropMode dropMode) | Sets the drop mode for this component. |
void | setEditingColumn(int aColumn) | Sets the editingColumn variable. |
void | setEditingRow(int aRow) | Sets the editingRow variable. |
void | setFillsViewportHeight(boolean fillsViewportHeight) | Sets whether or not this table is always made large enough to fill the height of an enclosing viewport. |
void | setGridColor(Color gridColor) | Sets the color used to draw grid lines to gridColor and redisplays. |
void | setIntercellSpacing(Dimension intercellSpacing) | Sets the rowMargin and the columnMargin -- the height and width of the space between cells -- tointercellSpacing. |
void | setModel(TableModel dataModel) | Sets the data model for this table to dataModel and registers with it for listener notifications from the new data model. |
void | setPreferredScrollableViewportSize(Dimension size) | Sets the preferred size of the viewport for this table. |
void | setRowHeight(int rowHeight) | Sets the height, in pixels, of all cells to rowHeight, revalidates, and repaints. |
void | setRowHeight(int row, int rowHeight) | Sets the height for row to rowHeight, revalidates, and repaints. |
void | setRowMargin(int rowMargin) | Sets the amount of empty space between cells in adjacent rows. |
void | setRowSelectionAllowed(boolean rowSelectionAllowed) | Sets whether the rows in this model can be selected. |
void | setRowSelectionInterval(int index0, int index1) | Selects the rows from index0 to index1, inclusive. |
void | setRowSorter(RowSorter<? extends TableModel> sorter) | Sets the RowSorter. |
void | setSelectionBackground(Color selectionBackground) | Sets the background color for selected cells. |
void | setSelectionForeground(Color selectionForeground) | Sets the foreground color for selected cells. |
void | setSelectionMode(int selectionMode) | Sets the table's selection mode to allow only single selections, a single contiguous interval, or multiple intervals. |
void | setSelectionModel(ListSelectionModel selectionModel) | Sets the row selection model for this table to selectionModel and registers for listener notifications from the new selection model. |
void | setShowGrid(boolean showGrid) | Sets whether the table draws grid lines around cells. |
void | setShowHorizontalLines(boolean showHorizontalLines) | Sets whether the table draws horizontal lines between cells. |
void | setShowVerticalLines(boolean showVerticalLines) | Sets whether the table draws vertical lines between cells. |
void | setSurrendersFocusOnKeystroke(boolean surrendersFocusOnKeystroke) | Sets whether editors in this JTable get the keyboard focus when an editor is activated as a result of the JTable forwarding keyboard events for a cell. |
void | setTableHeader(JTableHeader tableHeader) | Sets the tableHeader working with this JTable to newHeader. |
void | setUI(TableUI ui) | Sets the L&F object that renders this component and repaints. |
void | setUpdateSelectionOnSort(boolean update) | Specifies whether the selection should be updated after sorting. |
void | setValueAt(Object aValue, int row, int column) | Sets the value for the cell in the table model at row and column. |
void | sizeColumnsToFit(boolean lastColumnOnly) | Deprecated. |
void | sizeColumnsToFit(int resizingColumn) | Obsolete as of Java 2 platform v1.4. |
void | sorterChanged(RowSorterEvent e) | RowSorterListener notification that theRowSorter has changed in some way. |
void | tableChanged(TableModelEvent e) | Invoked when this table's TableModel generates a TableModelEvent. |
protected void | unconfigureEnclosingScrollPane() | Reverses the effect of configureEnclosingScrollPane by replacing the columnHeaderView of the enclosing scroll pane with null. |
void | updateUI() | Notification from the UIManager that the L&F has changed. |
void | valueChanged(ListSelectionEvent e) | Invoked when the row selection changes -- repaints to show the new selection. |
Methods declared in class javax.swing.JComponent
[addAncestorListener](JComponent.html#addAncestorListener%28javax.swing.event.AncestorListener%29), [addVetoableChangeListener](JComponent.html#addVetoableChangeListener%28java.beans.VetoableChangeListener%29), [computeVisibleRect](JComponent.html#computeVisibleRect%28java.awt.Rectangle%29), [contains](JComponent.html#contains%28int,int%29), [createToolTip](JComponent.html#createToolTip%28%29), [disable](JComponent.html#disable%28%29), [enable](JComponent.html#enable%28%29), [firePropertyChange](JComponent.html#firePropertyChange%28java.lang.String,boolean,boolean%29), [firePropertyChange](JComponent.html#firePropertyChange%28java.lang.String,int,int%29), [fireVetoableChange](JComponent.html#fireVetoableChange%28java.lang.String,java.lang.Object,java.lang.Object%29), [getActionForKeyStroke](JComponent.html#getActionForKeyStroke%28javax.swing.KeyStroke%29), [getActionMap](JComponent.html#getActionMap%28%29), [getAlignmentX](JComponent.html#getAlignmentX%28%29), [getAlignmentY](JComponent.html#getAlignmentY%28%29), [getAncestorListeners](JComponent.html#getAncestorListeners%28%29), [getAutoscrolls](JComponent.html#getAutoscrolls%28%29), [getBaseline](JComponent.html#getBaseline%28int,int%29), [getBaselineResizeBehavior](JComponent.html#getBaselineResizeBehavior%28%29), [getBorder](JComponent.html#getBorder%28%29), [getBounds](JComponent.html#getBounds%28java.awt.Rectangle%29), [getClientProperty](JComponent.html#getClientProperty%28java.lang.Object%29), [getComponentGraphics](JComponent.html#getComponentGraphics%28java.awt.Graphics%29), [getComponentPopupMenu](JComponent.html#getComponentPopupMenu%28%29), [getConditionForKeyStroke](JComponent.html#getConditionForKeyStroke%28javax.swing.KeyStroke%29), [getDebugGraphicsOptions](JComponent.html#getDebugGraphicsOptions%28%29), [getDefaultLocale](JComponent.html#getDefaultLocale%28%29), [getFontMetrics](JComponent.html#getFontMetrics%28java.awt.Font%29), [getGraphics](JComponent.html#getGraphics%28%29), [getHeight](JComponent.html#getHeight%28%29), [getInheritsPopupMenu](JComponent.html#getInheritsPopupMenu%28%29), [getInputMap](JComponent.html#getInputMap%28%29), [getInputMap](JComponent.html#getInputMap%28int%29), [getInputVerifier](JComponent.html#getInputVerifier%28%29), [getInsets](JComponent.html#getInsets%28%29), [getInsets](JComponent.html#getInsets%28java.awt.Insets%29), [getListeners](JComponent.html#getListeners%28java.lang.Class%29), [getLocation](JComponent.html#getLocation%28java.awt.Point%29), [getMaximumSize](JComponent.html#getMaximumSize%28%29), [getMinimumSize](JComponent.html#getMinimumSize%28%29), [getNextFocusableComponent](JComponent.html#getNextFocusableComponent%28%29), [getPopupLocation](JComponent.html#getPopupLocation%28java.awt.event.MouseEvent%29), [getPreferredSize](JComponent.html#getPreferredSize%28%29), [getRegisteredKeyStrokes](JComponent.html#getRegisteredKeyStrokes%28%29), [getRootPane](JComponent.html#getRootPane%28%29), [getSize](JComponent.html#getSize%28java.awt.Dimension%29), [getToolTipLocation](JComponent.html#getToolTipLocation%28java.awt.event.MouseEvent%29), [getToolTipText](JComponent.html#getToolTipText%28%29), [getTopLevelAncestor](JComponent.html#getTopLevelAncestor%28%29), [getTransferHandler](JComponent.html#getTransferHandler%28%29), [getVerifyInputWhenFocusTarget](JComponent.html#getVerifyInputWhenFocusTarget%28%29), [getVetoableChangeListeners](JComponent.html#getVetoableChangeListeners%28%29), [getVisibleRect](JComponent.html#getVisibleRect%28%29), [getWidth](JComponent.html#getWidth%28%29), [getX](JComponent.html#getX%28%29), [getY](JComponent.html#getY%28%29), [grabFocus](JComponent.html#grabFocus%28%29), [hide](JComponent.html#hide%28%29), [isDoubleBuffered](JComponent.html#isDoubleBuffered%28%29), [isLightweightComponent](JComponent.html#isLightweightComponent%28java.awt.Component%29), [isManagingFocus](JComponent.html#isManagingFocus%28%29), [isOpaque](JComponent.html#isOpaque%28%29), [isOptimizedDrawingEnabled](JComponent.html#isOptimizedDrawingEnabled%28%29), [isPaintingForPrint](JComponent.html#isPaintingForPrint%28%29), [isPaintingOrigin](JComponent.html#isPaintingOrigin%28%29), [isPaintingTile](JComponent.html#isPaintingTile%28%29), [isRequestFocusEnabled](JComponent.html#isRequestFocusEnabled%28%29), [isValidateRoot](JComponent.html#isValidateRoot%28%29), [paint](JComponent.html#paint%28java.awt.Graphics%29), [paintBorder](JComponent.html#paintBorder%28java.awt.Graphics%29), [paintChildren](JComponent.html#paintChildren%28java.awt.Graphics%29), [paintComponent](JComponent.html#paintComponent%28java.awt.Graphics%29), [paintImmediately](JComponent.html#paintImmediately%28int,int,int,int%29), [paintImmediately](JComponent.html#paintImmediately%28java.awt.Rectangle%29), [print](JComponent.html#print%28java.awt.Graphics%29), [printAll](JComponent.html#printAll%28java.awt.Graphics%29), [printBorder](JComponent.html#printBorder%28java.awt.Graphics%29), [printChildren](JComponent.html#printChildren%28java.awt.Graphics%29), [printComponent](JComponent.html#printComponent%28java.awt.Graphics%29), [processComponentKeyEvent](JComponent.html#processComponentKeyEvent%28java.awt.event.KeyEvent%29), [processKeyBinding](JComponent.html#processKeyBinding%28javax.swing.KeyStroke,java.awt.event.KeyEvent,int,boolean%29), [processKeyEvent](JComponent.html#processKeyEvent%28java.awt.event.KeyEvent%29), [processMouseEvent](JComponent.html#processMouseEvent%28java.awt.event.MouseEvent%29), [processMouseMotionEvent](JComponent.html#processMouseMotionEvent%28java.awt.event.MouseEvent%29), [putClientProperty](JComponent.html#putClientProperty%28java.lang.Object,java.lang.Object%29), [registerKeyboardAction](JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener,java.lang.String,javax.swing.KeyStroke,int%29), [registerKeyboardAction](JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener,javax.swing.KeyStroke,int%29), [removeAncestorListener](JComponent.html#removeAncestorListener%28javax.swing.event.AncestorListener%29), [removeVetoableChangeListener](JComponent.html#removeVetoableChangeListener%28java.beans.VetoableChangeListener%29), [repaint](JComponent.html#repaint%28long,int,int,int,int%29), [repaint](JComponent.html#repaint%28java.awt.Rectangle%29), [requestDefaultFocus](JComponent.html#requestDefaultFocus%28%29), [requestFocus](JComponent.html#requestFocus%28%29), [requestFocus](JComponent.html#requestFocus%28boolean%29), [requestFocusInWindow](JComponent.html#requestFocusInWindow%28%29), [requestFocusInWindow](JComponent.html#requestFocusInWindow%28boolean%29), [resetKeyboardActions](JComponent.html#resetKeyboardActions%28%29), [reshape](JComponent.html#reshape%28int,int,int,int%29), [revalidate](JComponent.html#revalidate%28%29), [scrollRectToVisible](JComponent.html#scrollRectToVisible%28java.awt.Rectangle%29), [setActionMap](JComponent.html#setActionMap%28javax.swing.ActionMap%29), [setAlignmentX](JComponent.html#setAlignmentX%28float%29), [setAlignmentY](JComponent.html#setAlignmentY%28float%29), [setAutoscrolls](JComponent.html#setAutoscrolls%28boolean%29), [setBackground](JComponent.html#setBackground%28java.awt.Color%29), [setBorder](JComponent.html#setBorder%28javax.swing.border.Border%29), [setComponentPopupMenu](JComponent.html#setComponentPopupMenu%28javax.swing.JPopupMenu%29), [setDebugGraphicsOptions](JComponent.html#setDebugGraphicsOptions%28int%29), [setDefaultLocale](JComponent.html#setDefaultLocale%28java.util.Locale%29), [setDoubleBuffered](JComponent.html#setDoubleBuffered%28boolean%29), [setEnabled](JComponent.html#setEnabled%28boolean%29), [setFocusTraversalKeys](JComponent.html#setFocusTraversalKeys%28int,java.util.Set%29), [setFont](JComponent.html#setFont%28java.awt.Font%29), [setForeground](JComponent.html#setForeground%28java.awt.Color%29), [setInheritsPopupMenu](JComponent.html#setInheritsPopupMenu%28boolean%29), [setInputMap](JComponent.html#setInputMap%28int,javax.swing.InputMap%29), [setInputVerifier](JComponent.html#setInputVerifier%28javax.swing.InputVerifier%29), [setMaximumSize](JComponent.html#setMaximumSize%28java.awt.Dimension%29), [setMinimumSize](JComponent.html#setMinimumSize%28java.awt.Dimension%29), [setNextFocusableComponent](JComponent.html#setNextFocusableComponent%28java.awt.Component%29), [setOpaque](JComponent.html#setOpaque%28boolean%29), [setPreferredSize](JComponent.html#setPreferredSize%28java.awt.Dimension%29), [setRequestFocusEnabled](JComponent.html#setRequestFocusEnabled%28boolean%29), [setToolTipText](JComponent.html#setToolTipText%28java.lang.String%29), [setTransferHandler](JComponent.html#setTransferHandler%28javax.swing.TransferHandler%29), [setUI](JComponent.html#setUI%28javax.swing.plaf.ComponentUI%29), [setVerifyInputWhenFocusTarget](JComponent.html#setVerifyInputWhenFocusTarget%28boolean%29), [setVisible](JComponent.html#setVisible%28boolean%29), [unregisterKeyboardAction](JComponent.html#unregisterKeyboardAction%28javax.swing.KeyStroke%29), [update](JComponent.html#update%28java.awt.Graphics%29)
Methods declared in class java.awt.Container
[add](../../java/awt/Container.html#add%28java.awt.Component%29), [add](../../java/awt/Container.html#add%28java.awt.Component,int%29), [add](../../java/awt/Container.html#add%28java.awt.Component,java.lang.Object%29), [add](../../java/awt/Container.html#add%28java.awt.Component,java.lang.Object,int%29), [add](../../java/awt/Container.html#add%28java.lang.String,java.awt.Component%29), [addContainerListener](../../java/awt/Container.html#addContainerListener%28java.awt.event.ContainerListener%29), [addImpl](../../java/awt/Container.html#addImpl%28java.awt.Component,java.lang.Object,int%29), [addPropertyChangeListener](../../java/awt/Container.html#addPropertyChangeListener%28java.beans.PropertyChangeListener%29), [addPropertyChangeListener](../../java/awt/Container.html#addPropertyChangeListener%28java.lang.String,java.beans.PropertyChangeListener%29), [applyComponentOrientation](../../java/awt/Container.html#applyComponentOrientation%28java.awt.ComponentOrientation%29), [areFocusTraversalKeysSet](../../java/awt/Container.html#areFocusTraversalKeysSet%28int%29), [countComponents](../../java/awt/Container.html#countComponents%28%29), [deliverEvent](../../java/awt/Container.html#deliverEvent%28java.awt.Event%29), [findComponentAt](../../java/awt/Container.html#findComponentAt%28int,int%29), [findComponentAt](../../java/awt/Container.html#findComponentAt%28java.awt.Point%29), [getComponent](../../java/awt/Container.html#getComponent%28int%29), [getComponentAt](../../java/awt/Container.html#getComponentAt%28int,int%29), [getComponentAt](../../java/awt/Container.html#getComponentAt%28java.awt.Point%29), [getComponentCount](../../java/awt/Container.html#getComponentCount%28%29), [getComponents](../../java/awt/Container.html#getComponents%28%29), [getComponentZOrder](../../java/awt/Container.html#getComponentZOrder%28java.awt.Component%29), [getContainerListeners](../../java/awt/Container.html#getContainerListeners%28%29), [getFocusTraversalKeys](../../java/awt/Container.html#getFocusTraversalKeys%28int%29), [getFocusTraversalPolicy](../../java/awt/Container.html#getFocusTraversalPolicy%28%29), [getLayout](../../java/awt/Container.html#getLayout%28%29), [getMousePosition](../../java/awt/Container.html#getMousePosition%28boolean%29), [insets](../../java/awt/Container.html#insets%28%29), [invalidate](../../java/awt/Container.html#invalidate%28%29), [isAncestorOf](../../java/awt/Container.html#isAncestorOf%28java.awt.Component%29), [isFocusCycleRoot](../../java/awt/Container.html#isFocusCycleRoot%28%29), [isFocusCycleRoot](../../java/awt/Container.html#isFocusCycleRoot%28java.awt.Container%29), [isFocusTraversalPolicyProvider](../../java/awt/Container.html#isFocusTraversalPolicyProvider%28%29), [isFocusTraversalPolicySet](../../java/awt/Container.html#isFocusTraversalPolicySet%28%29), [layout](../../java/awt/Container.html#layout%28%29), [list](../../java/awt/Container.html#list%28java.io.PrintStream,int%29), [list](../../java/awt/Container.html#list%28java.io.PrintWriter,int%29), [locate](../../java/awt/Container.html#locate%28int,int%29), [minimumSize](../../java/awt/Container.html#minimumSize%28%29), [paintComponents](../../java/awt/Container.html#paintComponents%28java.awt.Graphics%29), [preferredSize](../../java/awt/Container.html#preferredSize%28%29), [printComponents](../../java/awt/Container.html#printComponents%28java.awt.Graphics%29), [processContainerEvent](../../java/awt/Container.html#processContainerEvent%28java.awt.event.ContainerEvent%29), [processEvent](../../java/awt/Container.html#processEvent%28java.awt.AWTEvent%29), [remove](../../java/awt/Container.html#remove%28int%29), [remove](../../java/awt/Container.html#remove%28java.awt.Component%29), [removeAll](../../java/awt/Container.html#removeAll%28%29), [removeContainerListener](../../java/awt/Container.html#removeContainerListener%28java.awt.event.ContainerListener%29), [setComponentZOrder](../../java/awt/Container.html#setComponentZOrder%28java.awt.Component,int%29), [setFocusCycleRoot](../../java/awt/Container.html#setFocusCycleRoot%28boolean%29), [setFocusTraversalPolicy](../../java/awt/Container.html#setFocusTraversalPolicy%28java.awt.FocusTraversalPolicy%29), [setFocusTraversalPolicyProvider](../../java/awt/Container.html#setFocusTraversalPolicyProvider%28boolean%29), [setLayout](../../java/awt/Container.html#setLayout%28java.awt.LayoutManager%29), [transferFocusDownCycle](../../java/awt/Container.html#transferFocusDownCycle%28%29), [validate](../../java/awt/Container.html#validate%28%29), [validateTree](../../java/awt/Container.html#validateTree%28%29)
Methods declared in class java.awt.Component
[action](../../java/awt/Component.html#action%28java.awt.Event,java.lang.Object%29), [add](../../java/awt/Component.html#add%28java.awt.PopupMenu%29), [addComponentListener](../../java/awt/Component.html#addComponentListener%28java.awt.event.ComponentListener%29), [addFocusListener](../../java/awt/Component.html#addFocusListener%28java.awt.event.FocusListener%29), [addHierarchyBoundsListener](../../java/awt/Component.html#addHierarchyBoundsListener%28java.awt.event.HierarchyBoundsListener%29), [addHierarchyListener](../../java/awt/Component.html#addHierarchyListener%28java.awt.event.HierarchyListener%29), [addInputMethodListener](../../java/awt/Component.html#addInputMethodListener%28java.awt.event.InputMethodListener%29), [addKeyListener](../../java/awt/Component.html#addKeyListener%28java.awt.event.KeyListener%29), [addMouseListener](../../java/awt/Component.html#addMouseListener%28java.awt.event.MouseListener%29), [addMouseMotionListener](../../java/awt/Component.html#addMouseMotionListener%28java.awt.event.MouseMotionListener%29), [addMouseWheelListener](../../java/awt/Component.html#addMouseWheelListener%28java.awt.event.MouseWheelListener%29), [bounds](../../java/awt/Component.html#bounds%28%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image,int,int,java.awt.image.ImageObserver%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image,java.awt.image.ImageObserver%29), [coalesceEvents](../../java/awt/Component.html#coalesceEvents%28java.awt.AWTEvent,java.awt.AWTEvent%29), [contains](../../java/awt/Component.html#contains%28java.awt.Point%29), [createImage](../../java/awt/Component.html#createImage%28int,int%29), [createImage](../../java/awt/Component.html#createImage%28java.awt.image.ImageProducer%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int,int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int,int,java.awt.ImageCapabilities%29), [disableEvents](../../java/awt/Component.html#disableEvents%28long%29), [dispatchEvent](../../java/awt/Component.html#dispatchEvent%28java.awt.AWTEvent%29), [enable](../../java/awt/Component.html#enable%28boolean%29), [enableEvents](../../java/awt/Component.html#enableEvents%28long%29), [enableInputMethods](../../java/awt/Component.html#enableInputMethods%28boolean%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String,byte,byte%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String,char,char%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String,double,double%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String,float,float%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String,long,long%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String,short,short%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String,java.lang.Object,java.lang.Object%29), [getBackground](../../java/awt/Component.html#getBackground%28%29), [getBounds](../../java/awt/Component.html#getBounds%28%29), [getColorModel](../../java/awt/Component.html#getColorModel%28%29), [getComponentListeners](../../java/awt/Component.html#getComponentListeners%28%29), [getComponentOrientation](../../java/awt/Component.html#getComponentOrientation%28%29), [getCursor](../../java/awt/Component.html#getCursor%28%29), [getDropTarget](../../java/awt/Component.html#getDropTarget%28%29), [getFocusCycleRootAncestor](../../java/awt/Component.html#getFocusCycleRootAncestor%28%29), [getFocusListeners](../../java/awt/Component.html#getFocusListeners%28%29), [getFocusTraversalKeysEnabled](../../java/awt/Component.html#getFocusTraversalKeysEnabled%28%29), [getFont](../../java/awt/Component.html#getFont%28%29), [getForeground](../../java/awt/Component.html#getForeground%28%29), [getGraphicsConfiguration](../../java/awt/Component.html#getGraphicsConfiguration%28%29), [getHierarchyBoundsListeners](../../java/awt/Component.html#getHierarchyBoundsListeners%28%29), [getHierarchyListeners](../../java/awt/Component.html#getHierarchyListeners%28%29), [getIgnoreRepaint](../../java/awt/Component.html#getIgnoreRepaint%28%29), [getInputContext](../../java/awt/Component.html#getInputContext%28%29), [getInputMethodListeners](../../java/awt/Component.html#getInputMethodListeners%28%29), [getInputMethodRequests](../../java/awt/Component.html#getInputMethodRequests%28%29), [getKeyListeners](../../java/awt/Component.html#getKeyListeners%28%29), [getLocale](../../java/awt/Component.html#getLocale%28%29), [getLocation](../../java/awt/Component.html#getLocation%28%29), [getLocationOnScreen](../../java/awt/Component.html#getLocationOnScreen%28%29), [getMouseListeners](../../java/awt/Component.html#getMouseListeners%28%29), [getMouseMotionListeners](../../java/awt/Component.html#getMouseMotionListeners%28%29), [getMousePosition](../../java/awt/Component.html#getMousePosition%28%29), [getMouseWheelListeners](../../java/awt/Component.html#getMouseWheelListeners%28%29), [getName](../../java/awt/Component.html#getName%28%29), [getParent](../../java/awt/Component.html#getParent%28%29), [getPropertyChangeListeners](../../java/awt/Component.html#getPropertyChangeListeners%28%29), [getPropertyChangeListeners](../../java/awt/Component.html#getPropertyChangeListeners%28java.lang.String%29), [getSize](../../java/awt/Component.html#getSize%28%29), [getToolkit](../../java/awt/Component.html#getToolkit%28%29), [getTreeLock](../../java/awt/Component.html#getTreeLock%28%29), [gotFocus](../../java/awt/Component.html#gotFocus%28java.awt.Event,java.lang.Object%29), [handleEvent](../../java/awt/Component.html#handleEvent%28java.awt.Event%29), [hasFocus](../../java/awt/Component.html#hasFocus%28%29), [imageUpdate](../../java/awt/Component.html#imageUpdate%28java.awt.Image,int,int,int,int,int%29), [inside](../../java/awt/Component.html#inside%28int,int%29), [isBackgroundSet](../../java/awt/Component.html#isBackgroundSet%28%29), [isCursorSet](../../java/awt/Component.html#isCursorSet%28%29), [isDisplayable](../../java/awt/Component.html#isDisplayable%28%29), [isEnabled](../../java/awt/Component.html#isEnabled%28%29), [isFocusable](../../java/awt/Component.html#isFocusable%28%29), [isFocusOwner](../../java/awt/Component.html#isFocusOwner%28%29), [isFocusTraversable](../../java/awt/Component.html#isFocusTraversable%28%29), [isFontSet](../../java/awt/Component.html#isFontSet%28%29), [isForegroundSet](../../java/awt/Component.html#isForegroundSet%28%29), [isLightweight](../../java/awt/Component.html#isLightweight%28%29), [isMaximumSizeSet](../../java/awt/Component.html#isMaximumSizeSet%28%29), [isMinimumSizeSet](../../java/awt/Component.html#isMinimumSizeSet%28%29), [isPreferredSizeSet](../../java/awt/Component.html#isPreferredSizeSet%28%29), [isShowing](../../java/awt/Component.html#isShowing%28%29), [isValid](../../java/awt/Component.html#isValid%28%29), [isVisible](../../java/awt/Component.html#isVisible%28%29), [keyDown](../../java/awt/Component.html#keyDown%28java.awt.Event,int%29), [keyUp](../../java/awt/Component.html#keyUp%28java.awt.Event,int%29), [list](../../java/awt/Component.html#list%28%29), [list](../../java/awt/Component.html#list%28java.io.PrintStream%29), [list](../../java/awt/Component.html#list%28java.io.PrintWriter%29), [location](../../java/awt/Component.html#location%28%29), [lostFocus](../../java/awt/Component.html#lostFocus%28java.awt.Event,java.lang.Object%29), [mouseDown](../../java/awt/Component.html#mouseDown%28java.awt.Event,int,int%29), [mouseDrag](../../java/awt/Component.html#mouseDrag%28java.awt.Event,int,int%29), [mouseEnter](../../java/awt/Component.html#mouseEnter%28java.awt.Event,int,int%29), [mouseExit](../../java/awt/Component.html#mouseExit%28java.awt.Event,int,int%29), [mouseMove](../../java/awt/Component.html#mouseMove%28java.awt.Event,int,int%29), [mouseUp](../../java/awt/Component.html#mouseUp%28java.awt.Event,int,int%29), [move](../../java/awt/Component.html#move%28int,int%29), [nextFocus](../../java/awt/Component.html#nextFocus%28%29), [paintAll](../../java/awt/Component.html#paintAll%28java.awt.Graphics%29), [postEvent](../../java/awt/Component.html#postEvent%28java.awt.Event%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image,int,int,java.awt.image.ImageObserver%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image,java.awt.image.ImageObserver%29), [processComponentEvent](../../java/awt/Component.html#processComponentEvent%28java.awt.event.ComponentEvent%29), [processFocusEvent](../../java/awt/Component.html#processFocusEvent%28java.awt.event.FocusEvent%29), [processHierarchyBoundsEvent](../../java/awt/Component.html#processHierarchyBoundsEvent%28java.awt.event.HierarchyEvent%29), [processHierarchyEvent](../../java/awt/Component.html#processHierarchyEvent%28java.awt.event.HierarchyEvent%29), [processInputMethodEvent](../../java/awt/Component.html#processInputMethodEvent%28java.awt.event.InputMethodEvent%29), [processMouseWheelEvent](../../java/awt/Component.html#processMouseWheelEvent%28java.awt.event.MouseWheelEvent%29), [remove](../../java/awt/Component.html#remove%28java.awt.MenuComponent%29), [removeComponentListener](../../java/awt/Component.html#removeComponentListener%28java.awt.event.ComponentListener%29), [removeFocusListener](../../java/awt/Component.html#removeFocusListener%28java.awt.event.FocusListener%29), [removeHierarchyBoundsListener](../../java/awt/Component.html#removeHierarchyBoundsListener%28java.awt.event.HierarchyBoundsListener%29), [removeHierarchyListener](../../java/awt/Component.html#removeHierarchyListener%28java.awt.event.HierarchyListener%29), [removeInputMethodListener](../../java/awt/Component.html#removeInputMethodListener%28java.awt.event.InputMethodListener%29), [removeKeyListener](../../java/awt/Component.html#removeKeyListener%28java.awt.event.KeyListener%29), [removeMouseListener](../../java/awt/Component.html#removeMouseListener%28java.awt.event.MouseListener%29), [removeMouseMotionListener](../../java/awt/Component.html#removeMouseMotionListener%28java.awt.event.MouseMotionListener%29), [removeMouseWheelListener](../../java/awt/Component.html#removeMouseWheelListener%28java.awt.event.MouseWheelListener%29), [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.beans.PropertyChangeListener%29), [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.lang.String,java.beans.PropertyChangeListener%29), [repaint](../../java/awt/Component.html#repaint%28%29), [repaint](../../java/awt/Component.html#repaint%28int,int,int,int%29), [repaint](../../java/awt/Component.html#repaint%28long%29), [requestFocus](../../java/awt/Component.html#requestFocus%28boolean,java.awt.event.FocusEvent.Cause%29), [requestFocus](../../java/awt/Component.html#requestFocus%28java.awt.event.FocusEvent.Cause%29), [requestFocusInWindow](../../java/awt/Component.html#requestFocusInWindow%28java.awt.event.FocusEvent.Cause%29), [resize](../../java/awt/Component.html#resize%28int,int%29), [resize](../../java/awt/Component.html#resize%28java.awt.Dimension%29), [setBounds](../../java/awt/Component.html#setBounds%28int,int,int,int%29), [setBounds](../../java/awt/Component.html#setBounds%28java.awt.Rectangle%29), [setComponentOrientation](../../java/awt/Component.html#setComponentOrientation%28java.awt.ComponentOrientation%29), [setCursor](../../java/awt/Component.html#setCursor%28java.awt.Cursor%29), [setDropTarget](../../java/awt/Component.html#setDropTarget%28java.awt.dnd.DropTarget%29), [setFocusable](../../java/awt/Component.html#setFocusable%28boolean%29), [setFocusTraversalKeysEnabled](../../java/awt/Component.html#setFocusTraversalKeysEnabled%28boolean%29), [setIgnoreRepaint](../../java/awt/Component.html#setIgnoreRepaint%28boolean%29), [setLocale](../../java/awt/Component.html#setLocale%28java.util.Locale%29), [setLocation](../../java/awt/Component.html#setLocation%28int,int%29), [setLocation](../../java/awt/Component.html#setLocation%28java.awt.Point%29), [setMixingCutoutShape](../../java/awt/Component.html#setMixingCutoutShape%28java.awt.Shape%29), [setName](../../java/awt/Component.html#setName%28java.lang.String%29), [setSize](../../java/awt/Component.html#setSize%28int,int%29), [setSize](../../java/awt/Component.html#setSize%28java.awt.Dimension%29), [show](../../java/awt/Component.html#show%28%29), [show](../../java/awt/Component.html#show%28boolean%29), [size](../../java/awt/Component.html#size%28%29), [toString](../../java/awt/Component.html#toString%28%29), [transferFocus](../../java/awt/Component.html#transferFocus%28%29), [transferFocusBackward](../../java/awt/Component.html#transferFocusBackward%28%29), [transferFocusUpCycle](../../java/awt/Component.html#transferFocusUpCycle%28%29)
Field Details
AUTO_RESIZE_OFF
public static final int AUTO_RESIZE_OFF
Do not adjust column widths automatically; use a horizontal scrollbar instead.
See Also:
Constant Field ValuesAUTO_RESIZE_NEXT_COLUMN
public static final int AUTO_RESIZE_NEXT_COLUMN
When a column is adjusted in the UI, adjust the next column the opposite way.
See Also:
Constant Field ValuesAUTO_RESIZE_SUBSEQUENT_COLUMNS
public static final int AUTO_RESIZE_SUBSEQUENT_COLUMNS
During UI adjustment, change subsequent columns to preserve the total width; this is the default behavior.
See Also:
Constant Field ValuesAUTO_RESIZE_LAST_COLUMN
public static final int AUTO_RESIZE_LAST_COLUMN
During all resize operations, apply adjustments to the last column only.
See Also:
Constant Field ValuesAUTO_RESIZE_ALL_COLUMNS
public static final int AUTO_RESIZE_ALL_COLUMNS
During all resize operations, proportionately resize all columns.
See Also:
Constant Field ValuesdataModel
The
TableModel
of the table.columnModel
The
TableColumnModel
of the table.selectionModel
The
ListSelectionModel
of the table, used to keep track of row selections.rowHeight
protected int rowHeight
The height in pixels of each row in the table.rowMargin
protected int rowMargin
The height in pixels of the margin between the cells in each row.gridColor
protected Color gridColor
The color of the grid.showHorizontalLines
protected boolean showHorizontalLines
The table draws horizontal lines between cells ifshowHorizontalLines
is true.showVerticalLines
protected boolean showVerticalLines
The table draws vertical lines between cells ifshowVerticalLines
is true.autoResizeMode
protected int autoResizeMode
Determines if the table automatically resizes the width of the table's columns to take up the entire width of the table, and how it does the resizing.autoCreateColumnsFromModel
protected boolean autoCreateColumnsFromModel
The table will query theTableModel
to build the default set of columns if this is true.preferredViewportSize
protected Dimension preferredViewportSize
Used by theScrollable
interface to determine the initial visible area.rowSelectionAllowed
protected boolean rowSelectionAllowed
True if row selection is allowed in this table.cellSelectionEnabled
protected boolean cellSelectionEnabled
Obsolete as of Java 2 platform v1.3. Please use therowSelectionAllowed
property and thecolumnSelectionAllowed
property of thecolumnModel
instead. Or use the methodgetCellSelectionEnabled
.editorComp
protected transient Component editorComp
If editing, theComponent
that is handling the editing.cellEditor
The active cell editor object, that overwrites the screen real estate occupied by the current cell and allows the user to change its contents.
null
if the table isn't currently editing.editingColumn
protected transient int editingColumn
Identifies the column of the cell being edited.editingRow
protected transient int editingRow
Identifies the row of the cell being edited.defaultRenderersByColumnClass
A table of objects that display the contents of a cell, indexed by class as declared in
getColumnClass
in theTableModel
interface.defaultEditorsByColumnClass
A table of objects that display and edit the contents of a cell, indexed by class as declared in
getColumnClass
in theTableModel
interface.selectionForeground
protected Color selectionForeground
The foreground color of selected cells.selectionBackground
protected Color selectionBackground
The background color of selected cells.Constructor Details
JTable
public JTable()
Constructs a defaultJTable
that is initialized with a default data model, a default column model, and a default selection model.
See Also:
createDefaultDataModel(), createDefaultColumnModel(), createDefaultSelectionModel()JTable
Constructs a
JTable
that is initialized withdm
as the data model, a default column model, and a default selection model.
Parameters:
dm
- the data model for the table
See Also:
createDefaultColumnModel(), createDefaultSelectionModel()JTable
Constructs a
JTable
that is initialized withdm
as the data model,cm
as the column model, and a default selection model.
Parameters:
dm
- the data model for the table
cm
- the column model for the table
See Also:
createDefaultSelectionModel()JTable
Constructs a
JTable
that is initialized withdm
as the data model,cm
as the column model, andsm
as the selection model. If any of the parameters arenull
this method will initialize the table with the corresponding default model. TheautoCreateColumnsFromModel
flag is set to false ifcm
is non-null, otherwise it is set to true and the column model is populated with suitableTableColumns
for the columns indm
.
Parameters:
dm
- the data model for the table
cm
- the column model for the table
sm
- the row selection model for the table
See Also:
createDefaultDataModel(), createDefaultColumnModel(), createDefaultSelectionModel()JTable
public JTable(int numRows, int numColumns)
Constructs aJTable
withnumRows
andnumColumns
of empty cells usingDefaultTableModel
. The columns will have names of the form "A", "B", "C", etc.
Parameters:
numRows
- the number of rows the table holds
numColumns
- the number of columns the table holds
See Also:
DefaultTableModelJTable
Constructs a
JTable
to display the values in theVector
ofVectors
,rowData
, with column names,columnNames
. TheVectors
contained inrowData
should contain the values for that row. In other words, the value of the cell at row 1, column 5 can be obtained with the following code:
((Vector)rowData.elementAt(1)).elementAt(5);
Parameters:
rowData
- the data for the new table
columnNames
- names of each columnJTable
public JTable(Object[][] rowData,Object[] columnNames)
Constructs aJTable
to display the values in the two dimensional array,rowData
, with column names,columnNames
.rowData
is an array of rows, so the value of the cell at row 1, column 5 can be obtained with the following code:
rowData[1][5];
All rows must be of the same length ascolumnNames
.
Parameters:
rowData
- the data for the new table
columnNames
- names of each columnMethod Details
addNotify
public void addNotify()
Calls theconfigureEnclosingScrollPane
method.
Overrides:
[addNotify](JComponent.html#addNotify%28%29)
in class[JComponent](JComponent.html "class in javax.swing")
See Also:
configureEnclosingScrollPane()configureEnclosingScrollPane
protected void configureEnclosingScrollPane()
If thisJTable
is theviewportView
of an enclosingJScrollPane
(the usual situation), configure thisScrollPane
by, amongst other things, installing the table'stableHeader
as thecolumnHeaderView
of the scroll pane. When aJTable
is added to aJScrollPane
in the usual way, usingnew JScrollPane(myTable)
,addNotify
is called in theJTable
(when the table is added to the viewport).JTable
'saddNotify
method in turn calls this method, which is protected so that this default installation procedure can be overridden by a subclass.
See Also:
addNotify()removeNotify
public void removeNotify()
Calls theunconfigureEnclosingScrollPane
method.
Overrides:
[removeNotify](JComponent.html#removeNotify%28%29)
in class[JComponent](JComponent.html "class in javax.swing")
See Also:
unconfigureEnclosingScrollPane()unconfigureEnclosingScrollPane
protected void unconfigureEnclosingScrollPane()
Reverses the effect ofconfigureEnclosingScrollPane
by replacing thecolumnHeaderView
of the enclosing scroll pane withnull
.JTable
'sremoveNotify
method calls this method, which is protected so that this default uninstallation procedure can be overridden by a subclass.
Since:
1.3
See Also:
removeNotify(), configureEnclosingScrollPane()createScrollPaneForTable
Equivalent to
new JScrollPane(aTable)
.
Parameters:
aTable
- aJTable
to be used for the scroll pane
Returns:
aJScrollPane
created usingaTable
setRowHeight
@BeanProperty(description="The height of the specified row.")public void setRowHeight(int rowHeight)
Sets the height, in pixels, of all cells torowHeight
, revalidates, and repaints. The height of the cells will be equal to the row height minus the row margin.
Parameters:
rowHeight
- new row height
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifrowHeight
is less than 1
See Also:
getRowHeight()getRowHeight
public int getRowHeight()
Returns the height of a table row, in pixels.
Returns:
the height in pixels of a table row
See Also:
setRowHeight(int)setRowHeight
@BeanProperty(description="The height in pixels of the cells in
row
")public void setRowHeight(int row, int rowHeight)
Sets the height forrow
torowHeight
, revalidates, and repaints. The height of the cells in this row will be equal to the row height minus the row margin.
Parameters:
row
- the row whose height is being changed
rowHeight
- new row height, in pixels
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifrowHeight
is less than 1
Since:
1.3getRowHeight
public int getRowHeight(int row)
Returns the height, in pixels, of the cells inrow
.
Parameters:
row
- the row whose height is to be returned
Returns:
the height, in pixels, of the cells in the row
Since:
1.3setRowMargin
@BeanProperty(description="The amount of space between cells.")public void setRowMargin(int rowMargin)
Sets the amount of empty space between cells in adjacent rows.
Parameters:
rowMargin
- the number of pixels between cells in a row
See Also:
getRowMargin()getRowMargin
public int getRowMargin()
Gets the amount of empty space, in pixels, between cells. Equivalent to:getIntercellSpacing().height
.
Returns:
the number of pixels between cells in a row
See Also:
setRowMargin(int)setIntercellSpacing
@BeanProperty(bound=false,description="The spacing between the cells, drawn in the background color of the JTable.")public void setIntercellSpacing(Dimension intercellSpacing)
Sets therowMargin
and thecolumnMargin
-- the height and width of the space between cells -- tointercellSpacing
.
Parameters:
intercellSpacing
- aDimension
specifying the new width and height between cells
See Also:
getIntercellSpacing()getIntercellSpacing
public Dimension getIntercellSpacing()
Returns the horizontal and vertical space between cells. The default spacing is look and feel dependent.
Returns:
the horizontal and vertical spacing between cells
See Also:
setIntercellSpacing(java.awt.Dimension)setGridColor
Sets the color used to draw grid lines to
gridColor
and redisplays. The default color is look and feel dependent.
Parameters:
gridColor
- the new color of the grid lines
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifgridColor
isnull
See Also:
getGridColor()getGridColor
public Color getGridColor()
Returns the color used to draw grid lines. The default color is look and feel dependent.
Returns:
the color used to draw grid lines
See Also:
setGridColor(java.awt.Color)setShowGrid
@BeanProperty(description="The color used to draw the grid lines.")public void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells. IfshowGrid
is true it does; if it is false it doesn't. There is nogetShowGrid
method as this state is held in two variables --showHorizontalLines
andshowVerticalLines
-- each of which can be queried independently.
Parameters:
showGrid
- true if table view should draw grid lines
See Also:
setShowVerticalLines(boolean), setShowHorizontalLines(boolean)setShowHorizontalLines
@BeanProperty(description="Whether horizontal lines should be drawn in between the cells.")public void setShowHorizontalLines(boolean showHorizontalLines)
Sets whether the table draws horizontal lines between cells. IfshowHorizontalLines
is true it does; if it is false it doesn't.
Parameters:
showHorizontalLines
- true if table view should draw horizontal lines
See Also:
getShowHorizontalLines(), setShowGrid(boolean), setShowVerticalLines(boolean)setShowVerticalLines
@BeanProperty(description="Whether vertical lines should be drawn in between the cells.")public void setShowVerticalLines(boolean showVerticalLines)
Sets whether the table draws vertical lines between cells. IfshowVerticalLines
is true it does; if it is false it doesn't.
Parameters:
showVerticalLines
- true if table view should draw vertical lines
See Also:
getShowVerticalLines(), setShowGrid(boolean), setShowHorizontalLines(boolean)getShowHorizontalLines
public boolean getShowHorizontalLines()
Returns true if the table draws horizontal lines between cells, false if it doesn't. The default value is look and feel dependent.
Returns:
true if the table draws horizontal lines between cells, false if it doesn't
See Also:
setShowHorizontalLines(boolean)getShowVerticalLines
public boolean getShowVerticalLines()
Returns true if the table draws vertical lines between cells, false if it doesn't. The default value is look and feel dependent.
Returns:
true if the table draws vertical lines between cells, false if it doesn't
See Also:
setShowVerticalLines(boolean)setAutoResizeMode
@BeanProperty(enumerationValues={"JTable.AUTO_RESIZE_OFF","JTable.AUTO_RESIZE_NEXT_COLUMN","JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS","JTable.AUTO_RESIZE_LAST_COLUMN","JTable.AUTO_RESIZE_ALL_COLUMNS"},description="Whether the columns should adjust themselves automatically.")public void setAutoResizeMode(int mode)
Sets the table's auto resize mode when the table is resized. For further information on how the different resize modes work, seedoLayout().
Parameters:
mode
- One of 5 legal values: AUTO_RESIZE_OFF, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_SUBSEQUENT_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_ALL_COLUMNS
See Also:
getAutoResizeMode(), doLayout()getAutoResizeMode
public int getAutoResizeMode()
Returns the auto resize mode of the table. The default mode is AUTO_RESIZE_SUBSEQUENT_COLUMNS.
Returns:
the autoResizeMode of the table
See Also:
setAutoResizeMode(int), doLayout()setAutoCreateColumnsFromModel
@BeanProperty(description="Automatically populates the columnModel when a new TableModel is submitted.")public void setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel)
Sets this table'sautoCreateColumnsFromModel
flag. This method callscreateDefaultColumnsFromModel
ifautoCreateColumnsFromModel
changes from false to true.
Parameters:
autoCreateColumnsFromModel
- true ifJTable
should automatically create columns
See Also:
getAutoCreateColumnsFromModel(), createDefaultColumnsFromModel()getAutoCreateColumnsFromModel
public boolean getAutoCreateColumnsFromModel()
Determines whether the table will create default columns from the model. If true,setModel
will clear any existing columns and create new columns from the new model. Also, if the event in thetableChanged
notification specifies that the entire table changed, then the columns will be rebuilt. The default is true.
Returns:
the autoCreateColumnsFromModel of the table
See Also:
setAutoCreateColumnsFromModel(boolean), createDefaultColumnsFromModel()createDefaultColumnsFromModel
public void createDefaultColumnsFromModel()
Creates default columns for the table from the data model using thegetColumnCount
method defined in theTableModel
interface.
Clears any existing columns before creating the new columns based on information from the model.
See Also:
getAutoCreateColumnsFromModel()setDefaultRenderer
Sets a default cell renderer to be used if no renderer has been set in a
TableColumn
. If renderer isnull
, removes the default renderer for this column class.
Parameters:
columnClass
- set the default cell renderer for this columnClass
renderer
- default cell renderer to be used for this columnClass
See Also:
getDefaultRenderer(java.lang.Class<?>), setDefaultEditor(java.lang.Class<?>, javax.swing.table.TableCellEditor)getDefaultRenderer
Returns the cell renderer to be used when no renderer has been set in a
TableColumn
. During the rendering of cells the renderer is fetched from aHashtable
of entries according to the class of the cells in the column. If there is no entry for thiscolumnClass
the method returns the entry for the most specific superclass. TheJTable
installs entries forObject
,Number
, andBoolean
, all of which can be modified or replaced.
Parameters:
columnClass
- return the default cell renderer for this columnClass
Returns:
the renderer for this columnClass
See Also:
setDefaultRenderer(java.lang.Class<?>, javax.swing.table.TableCellRenderer), getColumnClass(int)setDefaultEditor
Sets a default cell editor to be used if no editor has been set in a
TableColumn
. If no editing is required in a table, or a particular column in a table, uses theisCellEditable
method in theTableModel
interface to ensure that thisJTable
will not start an editor in these columns. If editor isnull
, removes the default editor for this column class.
Parameters:
columnClass
- set the default cell editor for this columnClass
editor
- default cell editor to be used for this columnClass
See Also:
TableModel.isCellEditable(int, int), getDefaultEditor(java.lang.Class<?>), setDefaultRenderer(java.lang.Class<?>, javax.swing.table.TableCellRenderer)getDefaultEditor
Returns the editor to be used when no editor has been set in a
TableColumn
. During the editing of cells the editor is fetched from aHashtable
of entries according to the class of the cells in the column. If there is no entry for thiscolumnClass
the method returns the entry for the most specific superclass. TheJTable
installs entries forObject
,Number
, andBoolean
, all of which can be modified or replaced.
Parameters:
columnClass
- return the default cell editor for this columnClass
Returns:
the default cell editor to be used for this columnClass
See Also:
setDefaultEditor(java.lang.Class<?>, javax.swing.table.TableCellEditor), getColumnClass(int)setDragEnabled
@BeanProperty(bound=false,description="determines whether automatic drag handling is enabled")public void setDragEnabled(boolean b)
Turns on or off automatic drag handling. In order to enable automatic drag handling, this property should be set totrue
, and the table'sTransferHandler
needs to benon-null
. The default value of thedragEnabled
property isfalse
.
The job of honoring this property, and recognizing a user drag gesture, lies with the look and feel implementation, and in particular, the table'sTableUI
. When automatic drag handling is enabled, most look and feels (including those that subclassBasicLookAndFeel
) begin a drag and drop operation whenever the user presses the mouse button over an item (in single selection mode) or a selection (in other selection modes) and then moves the mouse a few pixels. Setting this property totrue
can therefore have a subtle effect on how selections behave.
If a look and feel is used that ignores this property, you can still begin a drag and drop operation by callingexportAsDrag
on the table'sTransferHandler
.
Parameters:
b
- whether or not to enable automatic drag handling
Throws:
[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")
- ifb
istrue
andGraphicsEnvironment.isHeadless()
returnstrue
Since:
1.4
See Also:
GraphicsEnvironment.isHeadless(), getDragEnabled(), JComponent.setTransferHandler(javax.swing.TransferHandler), TransferHandlergetDragEnabled
public boolean getDragEnabled()
Returns whether or not automatic drag handling is enabled.
Returns:
the value of thedragEnabled
property
Since:
1.4
See Also:
setDragEnabled(boolean)setDropMode
public final void setDropMode(DropMode dropMode)
Sets the drop mode for this component. For backward compatibility, the default for this property isDropMode.USE_SELECTION
. Usage of one of the other modes is recommended, however, for an improved user experience.DropMode.ON
, for instance, offers similar behavior of showing items as selected, but does so without affecting the actual selection in the table.
JTable
supports the following drop modes:
*DropMode.USE_SELECTION
*DropMode.ON
*DropMode.INSERT
*DropMode.INSERT_ROWS
*DropMode.INSERT_COLS
*DropMode.ON_OR_INSERT
*DropMode.ON_OR_INSERT_ROWS
*DropMode.ON_OR_INSERT_COLS
The drop mode is only meaningful if this component has aTransferHandler
that accepts drops.
Parameters:
dropMode
- the drop mode to use
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- if the drop mode is unsupported ornull
Since:
1.6
See Also:
getDropMode(), getDropLocation(), JComponent.setTransferHandler(javax.swing.TransferHandler), TransferHandlergetDropMode
public final DropMode getDropMode()
Returns the drop mode for this component.
Returns:
the drop mode for this component
Since:
1.6
See Also:
setDropMode(javax.swing.DropMode)getDropLocation
Returns the location that this component should visually indicate as the drop location during a DnD operation over the component, or
null
if no location is to currently be shown.
This method is not meant for querying the drop location from aTransferHandler
, as the drop location is only set after theTransferHandler
'scanImport
has returned and has allowed for the location to be shown.
When this property changes, a property change event with name "dropLocation" is fired by the component.
Returns:
the drop location
Since:
1.6
See Also:
setDropMode(javax.swing.DropMode), TransferHandler.canImport(TransferHandler.TransferSupport)setAutoCreateRowSorter
@BeanProperty(preferred=true,description="Whether or not to turn on sorting by default.")public void setAutoCreateRowSorter(boolean autoCreateRowSorter)
Specifies whether aRowSorter
should be created for the table whenever its model changes.
WhensetAutoCreateRowSorter(true)
is invoked, aTableRowSorter
is immediately created and installed on the table. While theautoCreateRowSorter
property remainstrue
, every time the model is changed, a newTableRowSorter
is created and set as the table's row sorter. The default value for theautoCreateRowSorter
property isfalse
.
Parameters:
autoCreateRowSorter
- whether or not aRowSorter
should be automatically created
Since:
1.6
See Also:
TableRowSortergetAutoCreateRowSorter
public boolean getAutoCreateRowSorter()
Returnstrue
if whenever the model changes, a newRowSorter
should be created and installed as the table's sorter; otherwise, returnsfalse
.
Returns:
true if aRowSorter
should be created when the model changes
Since:
1.6setUpdateSelectionOnSort
@BeanProperty(expert=true,description="Whether or not to update the selection on sorting")public void setUpdateSelectionOnSort(boolean update)
Specifies whether the selection should be updated after sorting. If true, on sorting the selection is reset such that the same rows, in terms of the model, remain selected. The default is true.
Parameters:
update
- whether or not to update the selection on sorting
Since:
1.6getUpdateSelectionOnSort
public boolean getUpdateSelectionOnSort()
Returns true if the selection should be updated after sorting.
Returns:
whether to update the selection on a sort
Since:
1.6setRowSorter
Sets the
RowSorter
.RowSorter
is used to provide sorting and filtering to aJTable
.
This method clears the selection and resets any variable row heights.
This method fires aPropertyChangeEvent
when appropriate, with the property name"rowSorter"
. For backward-compatibility, this method fires an additional event with the property name"sorter"
.
If the underlying model of theRowSorter
differs from that of thisJTable
undefined behavior will result.
Parameters:
sorter
- theRowSorter
;null
turns sorting off
Since:
1.6
See Also:
TableRowSortergetRowSorter
Returns the object responsible for sorting.
Returns:
the object responsible for sorting
Since:
1.6setSelectionMode
@BeanProperty(enumerationValues={"ListSelectionModel.SINGLE_SELECTION","ListSelectionModel.SINGLE_INTERVAL_SELECTION","ListSelectionModel.MULTIPLE_INTERVAL_SELECTION"},description="The selection mode used by the row and column selection models.")public void setSelectionMode(int selectionMode)
Sets the table's selection mode to allow only single selections, a single contiguous interval, or multiple intervals.
Note:JTable
provides all the methods for handling column and row selection. When setting states, such assetSelectionMode
, it not only updates the mode for the row selection model but also sets similar values in the selection model of thecolumnModel
. If you want to have the row and column selection models operating in different modes, set them both directly.
Both the row and column selection models forJTable
default to using aDefaultListSelectionModel
so thatJTable
works the same way as theJList
. See thesetSelectionMode
method inJList
for details about the modes.
Parameters:
selectionMode
- the mode used by the row and column selection models
See Also:
JList.setSelectionMode(int)setRowSelectionAllowed
@BeanProperty(visualUpdate=true,description="If true, an entire row is selected for each selected cell.")public void setRowSelectionAllowed(boolean rowSelectionAllowed)
Sets whether the rows in this model can be selected.
Parameters:
rowSelectionAllowed
- true if this model will allow row selection
See Also:
getRowSelectionAllowed()getRowSelectionAllowed
public boolean getRowSelectionAllowed()
Returns true if rows can be selected.
Returns:
true if rows can be selected, otherwise false
See Also:
setRowSelectionAllowed(boolean)setColumnSelectionAllowed
@BeanProperty(visualUpdate=true,description="If true, an entire column is selected for each selected cell.")public void setColumnSelectionAllowed(boolean columnSelectionAllowed)
Sets whether the columns in this model can be selected.
Parameters:
columnSelectionAllowed
- true if this model will allow column selection
See Also:
getColumnSelectionAllowed()getColumnSelectionAllowed
public boolean getColumnSelectionAllowed()
Returns true if columns can be selected.
Returns:
true if columns can be selected, otherwise false
See Also:
setColumnSelectionAllowed(boolean)setCellSelectionEnabled
@BeanProperty(visualUpdate=true,description="Select a rectangular region of cells rather than rows or columns.")public void setCellSelectionEnabled(boolean cellSelectionEnabled)
Sets whether this table allows both a column selection and a row selection to exist simultaneously. When set, the table treats the intersection of the row and column selection models as the selected cells. OverrideisCellSelected
to change this default behavior. This method is equivalent to setting both therowSelectionAllowed
property andcolumnSelectionAllowed
property of thecolumnModel
to the supplied value.
Parameters:
cellSelectionEnabled
- true if simultaneous row and column selection is allowed
See Also:
getCellSelectionEnabled(), isCellSelected(int, int)getCellSelectionEnabled
public boolean getCellSelectionEnabled()
Returns true if both row and column selection models are enabled. Equivalent togetRowSelectionAllowed() && getColumnSelectionAllowed()
.
Returns:
true if both row and column selection models are enabled
See Also:
setCellSelectionEnabled(boolean)selectAll
public void selectAll()
Selects all rows, columns, and cells in the table.clearSelection
public void clearSelection()
Deselects all selected columns and rows.setRowSelectionInterval
public void setRowSelectionInterval(int index0, int index1)
Selects the rows fromindex0
toindex1
, inclusive.
Parameters:
index0
- one end of the interval
index1
- the other end of the interval
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifindex0
orindex1
lie outside [0,getRowCount()
-1]setColumnSelectionInterval
public void setColumnSelectionInterval(int index0, int index1)
Selects the columns fromindex0
toindex1
, inclusive.
Parameters:
index0
- one end of the interval
index1
- the other end of the interval
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifindex0
orindex1
lie outside [0,getColumnCount()
-1]addRowSelectionInterval
public void addRowSelectionInterval(int index0, int index1)
Adds the rows fromindex0
toindex1
, inclusive, to the current selection.
Parameters:
index0
- one end of the interval
index1
- the other end of the interval
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifindex0
orindex1
lie outside [0,getRowCount()
-1]addColumnSelectionInterval
public void addColumnSelectionInterval(int index0, int index1)
Adds the columns fromindex0
toindex1
, inclusive, to the current selection.
Parameters:
index0
- one end of the interval
index1
- the other end of the interval
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifindex0
orindex1
lie outside [0,getColumnCount()
-1]removeRowSelectionInterval
public void removeRowSelectionInterval(int index0, int index1)
Deselects the rows fromindex0
toindex1
, inclusive.
Parameters:
index0
- one end of the interval
index1
- the other end of the interval
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifindex0
orindex1
lie outside [0,getRowCount()
-1]removeColumnSelectionInterval
public void removeColumnSelectionInterval(int index0, int index1)
Deselects the columns fromindex0
toindex1
, inclusive.
Parameters:
index0
- one end of the interval
index1
- the other end of the interval
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifindex0
orindex1
lie outside [0,getColumnCount()
-1]getSelectedRow
Returns the index of the first selected row, -1 if no row is selected.
Returns:
the index of the first selected rowgetSelectedColumn
Returns the index of the first selected column, -1 if no column is selected.
Returns:
the index of the first selected columngetSelectedRows
Returns the indices of all selected rows.
Returns:
an array of integers containing the indices of all selected rows, or an empty array if no row is selected
See Also:
getSelectedRow()getSelectedColumns
Returns the indices of all selected columns.
Returns:
an array of integers containing the indices of all selected columns, or an empty array if no column is selected
See Also:
getSelectedColumn()getSelectedRowCount
Returns the number of selected rows.
Returns:
the number of selected rows, 0 if no rows are selectedgetSelectedColumnCount
Returns the number of selected columns.
Returns:
the number of selected columns, 0 if no columns are selectedisRowSelected
public 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.
Parameters:
row
- a row in the row model
Returns:
true ifrow
is a valid index and the row at that index is selected (where 0 is the first row)isColumnSelected
public 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.
Parameters:
column
- the column in the column model
Returns:
true ifcolumn
is a valid index and the column at that index is selected (where 0 is the first column)isCellSelected
public 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.
Parameters:
row
- the row being queried
column
- the column being queried
Returns:
true ifrow
andcolumn
are valid indices and the cell at index(row, column)
is selected, where the first row and first column are at index 0changeSelection
public 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
andextend
. 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.
Parameters:
rowIndex
- affects the selection atrow
columnIndex
- affects the selection atcolumn
toggle
- see description above
extend
- if true, extend the current selection
Since:
1.3getSelectionForeground
public Color getSelectionForeground()
Returns the foreground color for selected cells.
Returns:
theColor
object for the foreground property
See Also:
setSelectionForeground(java.awt.Color), setSelectionBackground(java.awt.Color)setSelectionForeground
@BeanProperty(description="A default foreground color for selected cells.")public void setSelectionForeground(Color selectionForeground)
Sets the foreground color for selected cells. Cell renderers can use this color to render text and graphics for selected cells.
The default value of this property is defined by the look and feel implementation.
This is a JavaBeans bound property.
Parameters:
selectionForeground
- theColor
to use in the foreground for selected list items
See Also:
getSelectionForeground(), setSelectionBackground(java.awt.Color), JComponent.setForeground(java.awt.Color), JComponent.setBackground(java.awt.Color), JComponent.setFont(java.awt.Font)getSelectionBackground
public Color getSelectionBackground()
Returns the background color for selected cells.
Returns:
theColor
used for the background of selected list items
See Also:
setSelectionBackground(java.awt.Color), setSelectionForeground(java.awt.Color)setSelectionBackground
@BeanProperty(description="A default background color for selected cells.")public void setSelectionBackground(Color selectionBackground)
Sets the background color for selected cells. Cell renderers can use this color to the fill selected cells.
The default value of this property is defined by the look and feel implementation.
This is a JavaBeans bound property.
Parameters:
selectionBackground
- theColor
to use for the background of selected cells
See Also:
getSelectionBackground(), setSelectionForeground(java.awt.Color), JComponent.setForeground(java.awt.Color), JComponent.setBackground(java.awt.Color), JComponent.setFont(java.awt.Font)getColumn
Returns the
TableColumn
object for the column in the table whose identifier is equal toidentifier
, when compared usingequals
.
Parameters:
identifier
- the identifier object
Returns:
theTableColumn
object that matches the identifier
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifidentifier
isnull
or noTableColumn
has this identifierconvertColumnIndexToModel
public int convertColumnIndexToModel(int viewColumnIndex)
Maps the index of the column in the view atviewColumnIndex
to the index of the column in the table model. Returns the index of the corresponding column in the model. IfviewColumnIndex
is less than zero, returnsviewColumnIndex
.
Parameters:
viewColumnIndex
- the index of the column in the view
Returns:
the index of the corresponding column in the model
See Also:
convertColumnIndexToView(int)convertColumnIndexToView
public int convertColumnIndexToView(int modelColumnIndex)
Maps the index of the column in the table model atmodelColumnIndex
to the index of the column in the view. Returns the index of the corresponding column in the view; returns -1 if this column is not being displayed. IfmodelColumnIndex
is less than zero, returnsmodelColumnIndex
.
Parameters:
modelColumnIndex
- the index of the column in the model
Returns:
the index of the corresponding column in the view
See Also:
convertColumnIndexToModel(int)convertRowIndexToView
public int convertRowIndexToView(int modelRowIndex)
Maps the index of the row in terms of theTableModel
to the view. If the contents of the model are not sorted the model and view indices are the same.
Parameters:
modelRowIndex
- the index of the row in terms of the model
Returns:
the index of the corresponding row in the view, or -1 if the row isn't visible
Throws:
[IndexOutOfBoundsException](../../../java.base/java/lang/IndexOutOfBoundsException.html "class in java.lang")
- if sorting is enabled and passed an index outside the number of rows of theTableModel
Since:
1.6
See Also:
TableRowSorterconvertRowIndexToModel
public int convertRowIndexToModel(int viewRowIndex)
Maps the index of the row in terms of the view to the underlyingTableModel
. If the contents of the model are not sorted the model and view indices are the same.
Parameters:
viewRowIndex
- the index of the row in the view
Returns:
the index of the corresponding row in the model
Throws:
[IndexOutOfBoundsException](../../../java.base/java/lang/IndexOutOfBoundsException.html "class in java.lang")
- if sorting is enabled and passed an index outside the range of theJTable
as determined by the methodgetRowCount
Since:
1.6
See Also:
TableRowSorter, getRowCount()getRowCount
Returns the number of rows that can be shown in the
JTable
, given unlimited space. If aRowSorter
with a filter has been specified, the number of rows returned may differ from that of the underlyingTableModel
.
Returns:
the number of rows shown in theJTable
See Also:
getColumnCount()getColumnCount
Returns the number of columns in the column model. Note that this may be different from the number of columns in the table model.
Returns:
the number of columns in the table
See Also:
getRowCount(), removeColumn(javax.swing.table.TableColumn)getColumnName
public String getColumnName(int column)
Returns the name of the column appearing in the view at column positioncolumn
.
Parameters:
column
- the column in the view being queried
Returns:
the name of the column at positioncolumn
in the view where the first column is column 0getColumnClass
public Class<?> getColumnClass(int column)
Returns the type of the column appearing in the view at column positioncolumn
.
Parameters:
column
- the column in the view being queried
Returns:
the type of the column at positioncolumn
in the view where the first column is column 0getValueAt
public Object getValueAt(int row, int column)
Returns the cell value atrow
andcolumn
.
Note: The column is specified in the table view's display order, and not in theTableModel
'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.
Parameters:
row
- the row whose value is to be queried
column
- the column whose value is to be queried
Returns:
the Object at the specified cellsetValueAt
public void setValueAt(Object aValue, int row, int column)
Sets the value for the cell in the table model atrow
andcolumn
.
Note: The column is specified in the table view's display order, and not in theTableModel
'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.
Parameters:
aValue
- the new value
row
- the row of the cell to be changed
column
- the column of the cell to be changed
See Also:
getValueAt(int, int)isCellEditable
public boolean isCellEditable(int row, int column)
Returns true if the cell atrow
andcolumn
is editable. Otherwise, invokingsetValueAt
on the cell will have no effect.
Note: The column is specified in the table view's display order, and not in theTableModel
'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.
Parameters:
row
- the row whose value is to be queried
column
- the column whose value is to be queried
Returns:
true if the cell is editable
See Also:
setValueAt(java.lang.Object, int, int)addColumn
Appends
aColumn
to the end of the array of columns held by thisJTable
's column model. If the column name ofaColumn
isnull
, sets the column name ofaColumn
to the name returned bygetModel().getColumnName()
.
To add a column to thisJTable
to display themodelColumn
'th column of data in the model with a givenwidth
,cellRenderer
, andcellEditor
you can use:
addColumn(new TableColumn(modelColumn, width, cellRenderer, cellEditor));
[Any of theTableColumn
constructors can be used instead of this one.] The model column number is stored inside theTableColumn
and is used during rendering and editing to locate the appropriates data values in the model. The model column number does not change when columns are reordered in the view.
Parameters:
aColumn
- theTableColumn
to be added
See Also:
removeColumn(javax.swing.table.TableColumn)removeColumn
public void removeColumn(TableColumn aColumn)
RemovesaColumn
from thisJTable
's array of columns. Note: this method does not remove the column of data from the model; it just removes theTableColumn
that was responsible for displaying it.
Parameters:
aColumn
- theTableColumn
to be removed
See Also:
addColumn(javax.swing.table.TableColumn)moveColumn
public void moveColumn(int column, int targetColumn)
Moves the columncolumn
to the position currently occupied by the columntargetColumn
in the view. The old column attargetColumn
is shifted left or right to make room.
Parameters:
column
- the index of column to be moved
targetColumn
- the new index of the columncolumnAtPoint
public int columnAtPoint(Point point)
Returns the index of the column thatpoint
lies in, or -1 if the result is not in the range [0,getColumnCount()
-1].
Parameters:
point
- the location of interest
Returns:
the index of the column thatpoint
lies in, or -1 if the result is not in the range [0,getColumnCount()
-1]
See Also:
rowAtPoint(java.awt.Point)rowAtPoint
public int rowAtPoint(Point point)
Returns the index of the row thatpoint
lies in, or -1 if the result is not in the range [0,getRowCount()
-1].
Parameters:
point
- the location of interest
Returns:
the index of the row thatpoint
lies in, or -1 if the result is not in the range [0,getRowCount()
-1]
See Also:
columnAtPoint(java.awt.Point)getCellRect
public Rectangle getCellRect(int row, int column, boolean includeSpacing)
Returns a rectangle for the cell that lies at the intersection ofrow
andcolumn
. IfincludeSpacing
is true then the value returned has the full height and width of the row and column specified. If it is false, the returned rectangle is inset by the intercell spacing to return the true bounds of the rendering or editing component as it will be set during rendering.
If the column index is valid but the row index is less than zero the method returns a rectangle with they
andheight
values set appropriately and thex
andwidth
values both set to zero. In general, when either the row or column indices indicate a cell outside the appropriate range, the method returns a rectangle depicting the closest edge of the closest cell that is within the table's range. When both row and column indices are out of range the returned rectangle covers the closest point of the closest cell.
In all cases, calculations that use this method to calculate results along one axis will not fail because of anomalies in calculations along the other axis. When the cell is not valid theincludeSpacing
parameter is ignored.
Parameters:
row
- the row index where the desired cell is located
column
- the column index where the desired cell is located in the display; this is not necessarily the same as the column index in the data model for the table; theconvertColumnIndexToView(int) method may be used to convert a data model column index to a display column index
includeSpacing
- if false, return the true cell bounds - computed by subtracting the intercell spacing from the height and widths of the column and row models
Returns:
the rectangle containing the cell at locationrow
,column
See Also:
getIntercellSpacing()doLayout
public void doLayout()
Causes this table to lay out its rows and columns. Overridden so that columns can be resized to accommodate a change in the size of a containing parent. Resizes one or more of the columns in the table so that the total width of all of thisJTable
's columns is equal to the width of the table.
Before the layout begins the method gets theresizingColumn
of thetableHeader
. When the method is called as a result of the resizing of an enclosing window, theresizingColumn
isnull
. This means that resizing has taken place "outside" theJTable
and the change - or "delta" - should be distributed to all of the columns regardless of thisJTable
's automatic resize mode.
If theresizingColumn
is notnull
, it is one of the columns in the table that has changed size rather than the table itself. In this case the auto-resize modes govern the way the extra (or deficit) space is distributed amongst the available columns.
The modes are:
* AUTO_RESIZE_OFF: Don't automatically adjust the column's widths at all. Use a horizontal scrollbar to accommodate the columns when their sum exceeds the width of theViewport
. If theJTable
is not enclosed in aJScrollPane
this may leave parts of the table invisible.
* AUTO_RESIZE_NEXT_COLUMN: Use just the column after the resizing column. This results in the "boundary" or divider between adjacent cells being independently adjustable.
* AUTO_RESIZE_SUBSEQUENT_COLUMNS: Use all columns after the one being adjusted to absorb the changes. This is the default behavior.
* AUTO_RESIZE_LAST_COLUMN: Automatically adjust the size of the last column only. If the bounds of the last column prevent the desired size from being allocated, set the width of the last column to the appropriate limit and make no further adjustments.
* AUTO_RESIZE_ALL_COLUMNS: Spread the delta amongst all the columns in theJTable
, including the one that is being adjusted.
Note: When aJTable
makes adjustments to the widths of the columns it respects their minimum and maximum values absolutely. It is therefore possible that, even after this method is called, the total width of the columns is still not equal to the width of the table. When this happens theJTable
does not put itself in AUTO_RESIZE_OFF mode to bring up a scroll bar, or break other commitments of its current auto-resize mode -- instead it allows its bounds to be set larger (or smaller) than the total of the column minimum or maximum, meaning, either that there will not be enough room to display all of the columns, or that the columns will not fill theJTable
's bounds. These respectively, result in the clipping of some columns or an area being painted in theJTable
's background color during painting.
The mechanism for distributing the delta amongst the available columns is provided in a private method in theJTable
class:
adjustSizes(long targetSize, final Resizable3 r, boolean inverse)an explanation of which is provided in the following section.
Resizable3
is a private interface that allows any data structure containing a collection of elements with a size, preferred size, maximum size and minimum size to have its elements manipulated by the algorithm.Distributing the delta
Overview
Call "DELTA" the difference between the target size and the sum of the preferred sizes of the elements in r. The individual sizes are calculated by taking the original preferred sizes and adding a share of the DELTA - that share being based on how far each preferred size is from its limiting bound (minimum or maximum).
Definition
Call the individual constraints min[i], max[i], and pref[i].
Call their respective sums: MIN, MAX, and PREF.
Each new size will be calculated using:
size[i] = pref[i] + delta[i]where each individual delta[i] is calculated according to:
If (DELTA < 0) we are in shrink mode where:
DELTA
delta[i] = ------------ * (pref[i] - min[i])
(PREF - MIN)If (DELTA > 0) we are in expand mode where:
DELTA
delta[i] = ------------ * (max[i] - pref[i])
(MAX - PREF)The overall effect is that the total size moves that same percentage, k, towards the total minimum or maximum and that percentage guarantees accommodation of the required space, DELTA.
Details
Naive evaluation of the formulae presented here would be subject to the aggregated rounding errors caused by doing this operation in finite precision (using ints). To deal with this, the multiplying factor above, is constantly recalculated and this takes account of the rounding errors in the previous iterations. The result is an algorithm that produces a set of integers whose values exactly sum to the supplied
targetSize
, and does so by spreading the rounding errors evenly over the given elements.When the MAX and MIN bounds are hit
When
targetSize
is outside the [MIN, MAX] range, the algorithm sets all sizes to their appropriate limiting value (maximum or minimum).
Overrides:
[doLayout](../../java/awt/Container.html#doLayout%28%29)
in class[Container](../../java/awt/Container.html "class in java.awt")
See Also:
LayoutManager.layoutContainer(java.awt.Container), Container.setLayout(java.awt.LayoutManager), Container.validate()sizeColumnsToFit
@Deprecated public void sizeColumnsToFit(boolean lastColumnOnly)
Sizes the table columns to fit the available space.
Parameters:
lastColumnOnly
- determines whether to resize last column only
See Also:
doLayout()sizeColumnsToFit
public void sizeColumnsToFit(int resizingColumn)
Obsolete as of Java 2 platform v1.4. Please use thedoLayout()
method instead.
Parameters:
resizingColumn
- the column whose resizing made this adjustment necessary or -1 if there is no such column
See Also:
doLayout()getToolTipText
Overrides
JComponent
'sgetToolTipText
method in order to allow the renderer's tips to be used if it has text set.
Note: ForJTable
to properly display tooltips of its renderersJTable
must be a registered component with theToolTipManager
. This is done automatically ininitializeLocalVars
, but if at a later pointJTable
is toldsetToolTipText(null)
it will unregister the table component, and no tips from renderers will display anymore.
Overrides:
[getToolTipText](JComponent.html#getToolTipText%28java.awt.event.MouseEvent%29)
in class[JComponent](JComponent.html "class in javax.swing")
Parameters:
event
- theMouseEvent
that initiated theToolTip
display
Returns:
a string containing the tooltip
See Also:
JComponent.getToolTipText()setSurrendersFocusOnKeystroke
public void setSurrendersFocusOnKeystroke(boolean surrendersFocusOnKeystroke)
Sets whether editors in this JTable get the keyboard focus when an editor is activated as a result of the JTable forwarding keyboard events for a cell. By default, this property is false, and the JTable retains the focus unless the cell is clicked.
Parameters:
surrendersFocusOnKeystroke
- true if the editor should get the focus when keystrokes cause the editor to be activated
Since:
1.4
See Also:
getSurrendersFocusOnKeystroke()getSurrendersFocusOnKeystroke
public boolean getSurrendersFocusOnKeystroke()
Returns true if the editor should get the focus when keystrokes cause the editor to be activated
Returns:
true if the editor should get the focus when keystrokes cause the editor to be activated
Since:
1.4
See Also:
setSurrendersFocusOnKeystroke(boolean)editCellAt
public boolean editCellAt(int row, int column)
Programmatically starts editing the cell atrow
andcolumn
, if those indices are in the valid range, and the cell at those indices is editable. Note that this is a convenience method foreditCellAt(int, int, null)
.
Parameters:
row
- the row to be edited
column
- the column to be edited
Returns:
false if for any reason the cell cannot be edited, or if the indices are invalideditCellAt
public boolean editCellAt(int row, int column,EventObject e)
Programmatically starts editing the cell atrow
andcolumn
, if those indices are in the valid range, and the cell at those indices is editable. To prevent theJTable
from editing a particular table, column or cell value, return false from theisCellEditable
method in theTableModel
interface.
Parameters:
row
- the row to be edited
column
- the column to be edited
e
- event to pass intoshouldSelectCell
; note that as of Java 2 platform v1.2, the call toshouldSelectCell
is no longer made
Returns:
false if for any reason the cell cannot be edited, or if the indices are invalidisEditing
Returns true if a cell is being edited.
Returns:
true if the table is editing a cell
See Also:
editingColumn, editingRowgetEditorComponent
Returns the component that is handling the editing session. If nothing is being edited, returns null.
Returns:
Component handling editing sessiongetEditingColumn
public int getEditingColumn()
Returns the index of the column that contains the cell currently being edited. If nothing is being edited, returns -1.
Returns:
the index of the column that contains the cell currently being edited; returns -1 if nothing being edited
See Also:
editingRowgetEditingRow
public int getEditingRow()
Returns the index of the row that contains the cell currently being edited. If nothing is being edited, returns -1.
Returns:
the index of the row that contains the cell currently being edited; returns -1 if nothing being edited
See Also:
editingColumngetUI
Returns the L&F object that renders this component.
Overrides:
[getUI](JComponent.html#getUI%28%29)
in class[JComponent](JComponent.html "class in javax.swing")
Returns:
theTableUI
object that renders this componentsetUI
Sets the L&F object that renders this component and repaints.
Parameters:
ui
- the TableUI L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)updateUI
public void updateUI()
Notification from theUIManager
that the L&F has changed. Replaces the current UI object with the latest version from theUIManager
.
Overrides:
[updateUI](JComponent.html#updateUI%28%29)
in class[JComponent](JComponent.html "class in javax.swing")
See Also:
JComponent.updateUI()getUIClassID
Returns the suffix used to construct the name of the L&F class used to render this component.
Overrides:
[getUIClassID](JComponent.html#getUIClassID%28%29)
in class[JComponent](JComponent.html "class in javax.swing")
Returns:
the string "TableUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)setModel
Sets the data model for this table to
dataModel
and registers with it for listener notifications from the new data model.
Parameters:
dataModel
- the new data source for this table
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifdataModel
isnull
See Also:
getModel()getModel
Returns the
TableModel
that provides the data displayed by thisJTable
.
Returns:
theTableModel
that provides the data displayed by thisJTable
See Also:
setModel(javax.swing.table.TableModel)setColumnModel
Sets the column model for this table to
columnModel
and registers for listener notifications from the new column model. Also sets the column model of theJTableHeader
tocolumnModel
.
Parameters:
columnModel
- the new data source for this table
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifcolumnModel
isnull
See Also:
getColumnModel()getColumnModel
Returns the
TableColumnModel
that contains all column information of this table.
Returns:
the object that provides the column state of the table
See Also:
setColumnModel(javax.swing.table.TableColumnModel)setSelectionModel
Sets the row selection model for this table to
selectionModel
and registers for listener notifications from the new selection model.
Parameters:
selectionModel
- the new selection model
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifselectionModel
isnull
See Also:
getSelectionModel()getSelectionModel
Returns the
ListSelectionModel
that is used to maintain row selection state.
Returns:
the object that provides row selection state,null
if row selection is not allowed
See Also:
setSelectionModel(javax.swing.ListSelectionModel)sorterChanged
RowSorterListener
notification that theRowSorter
has changed in some way.
Specified by:
[sorterChanged](event/RowSorterListener.html#sorterChanged%28javax.swing.event.RowSorterEvent%29)
in interface[RowSorterListener](event/RowSorterListener.html "interface in javax.swing.event")
Parameters:
e
- theRowSorterEvent
describing the change
Throws:
[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")
- ife
isnull
Since:
1.6tableChanged
Invoked when this table's
TableModel
generates aTableModelEvent
. TheTableModelEvent
should be constructed in the coordinate system of the model; the appropriate mapping to the view coordinate system is performed by thisJTable
when it receives the event.
Application code will not use these methods explicitly, they are used internally byJTable
.
Note that as of 1.3, this method clears the selection, if any.
Specified by:
[tableChanged](event/TableModelListener.html#tableChanged%28javax.swing.event.TableModelEvent%29)
in interface[TableModelListener](event/TableModelListener.html "interface in javax.swing.event")
Parameters:
e
- aTableModelEvent
to notify listener that a table model has changedcolumnAdded
Invoked when a column is added to the table column model.
Application code will not use these methods explicitly, they are used internally by JTable.
Specified by:
[columnAdded](event/TableColumnModelListener.html#columnAdded%28javax.swing.event.TableColumnModelEvent%29)
in interface[TableColumnModelListener](event/TableColumnModelListener.html "interface in javax.swing.event")
Parameters:
e
- aTableColumnModelEvent
See Also:
TableColumnModelListenercolumnRemoved
Invoked when a column is removed from the table column model.
Application code will not use these methods explicitly, they are used internally by JTable.
Specified by:
[columnRemoved](event/TableColumnModelListener.html#columnRemoved%28javax.swing.event.TableColumnModelEvent%29)
in interface[TableColumnModelListener](event/TableColumnModelListener.html "interface in javax.swing.event")
Parameters:
e
- aTableColumnModelEvent
See Also:
TableColumnModelListenercolumnMoved
Invoked when a column is repositioned. If a cell is being edited, then editing is stopped and the cell is redrawn.
Application code will not use these methods explicitly, they are used internally by JTable.
Specified by:
[columnMoved](event/TableColumnModelListener.html#columnMoved%28javax.swing.event.TableColumnModelEvent%29)
in interface[TableColumnModelListener](event/TableColumnModelListener.html "interface in javax.swing.event")
Parameters:
e
- the event received
See Also:
TableColumnModelListenercolumnMarginChanged
public void columnMarginChanged(ChangeEvent e)
Invoked when a column is moved due to a margin change. If a cell is being edited, then editing is stopped and the cell is redrawn.
Application code will not use these methods explicitly, they are used internally by JTable.
Specified by:
[columnMarginChanged](event/TableColumnModelListener.html#columnMarginChanged%28javax.swing.event.ChangeEvent%29)
in interface[TableColumnModelListener](event/TableColumnModelListener.html "interface in javax.swing.event")
Parameters:
e
- the event received
See Also:
TableColumnModelListenercolumnSelectionChanged
Invoked when the selection model of the
TableColumnModel
is changed.
Application code will not use these methods explicitly, they are used internally by JTable.
Specified by:
[columnSelectionChanged](event/TableColumnModelListener.html#columnSelectionChanged%28javax.swing.event.ListSelectionEvent%29)
in interface[TableColumnModelListener](event/TableColumnModelListener.html "interface in javax.swing.event")
Parameters:
e
- the event received
See Also:
TableColumnModelListenervalueChanged
Invoked when the row selection changes -- repaints to show the new selection.
Application code will not use these methods explicitly, they are used internally by JTable.
Specified by:
[valueChanged](event/ListSelectionListener.html#valueChanged%28javax.swing.event.ListSelectionEvent%29)
in interface[ListSelectionListener](event/ListSelectionListener.html "interface in javax.swing.event")
Parameters:
e
- the event received
See Also:
ListSelectionListenereditingStopped
Invoked when editing is finished. The changes are saved and the editor is discarded.
Application code will not use these methods explicitly, they are used internally by JTable.
Specified by:
[editingStopped](event/CellEditorListener.html#editingStopped%28javax.swing.event.ChangeEvent%29)
in interface[CellEditorListener](event/CellEditorListener.html "interface in javax.swing.event")
Parameters:
e
- the event received
See Also:
CellEditorListenereditingCanceled
Invoked when editing is canceled. The editor object is discarded and the cell is rendered once again.
Application code will not use these methods explicitly, they are used internally by JTable.
Specified by:
[editingCanceled](event/CellEditorListener.html#editingCanceled%28javax.swing.event.ChangeEvent%29)
in interface[CellEditorListener](event/CellEditorListener.html "interface in javax.swing.event")
Parameters:
e
- the event received
See Also:
CellEditorListenersetPreferredScrollableViewportSize
Sets the preferred size of the viewport for this table.
Parameters:
size
- aDimension
object specifying thepreferredSize
of aJViewport
whose view is this table
See Also:
Scrollable.getPreferredScrollableViewportSize()getPreferredScrollableViewportSize
public Dimension getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for this table.
Specified by:
[getPreferredScrollableViewportSize](Scrollable.html#getPreferredScrollableViewportSize%28%29)
in interface[Scrollable](Scrollable.html "interface in javax.swing")
Returns:
aDimension
object containing thepreferredSize
of theJViewport
which displays this table
See Also:
Scrollable.getPreferredScrollableViewportSize()getScrollableUnitIncrement
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
Returns the scroll increment (in pixels) that completely exposes one new row or column (depending on the orientation).
This method is called each time the user requests a unit scroll.
Specified by:
[getScrollableUnitIncrement](Scrollable.html#getScrollableUnitIncrement%28java.awt.Rectangle,int,int%29)
in interface[Scrollable](Scrollable.html "interface in javax.swing")
Parameters:
visibleRect
- the view area visible within the viewport
orientation
- eitherSwingConstants.VERTICAL
orSwingConstants.HORIZONTAL
direction
- less than zero to scroll up/left, greater than zero for down/right
Returns:
the "unit" increment for scrolling in the specified direction
See Also:
Scrollable.getScrollableUnitIncrement(java.awt.Rectangle, int, int)getScrollableBlockIncrement
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
ReturnsvisibleRect.height
orvisibleRect.width
, depending on this table's orientation. Note that as of Swing 1.1.1 (Java 2 v 1.2.2) the value returned will ensure that the viewport is cleanly aligned on a row boundary.
Specified by:
[getScrollableBlockIncrement](Scrollable.html#getScrollableBlockIncrement%28java.awt.Rectangle,int,int%29)
in interface[Scrollable](Scrollable.html "interface in javax.swing")
Parameters:
visibleRect
- The view area visible within the viewport
orientation
- Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction
- Less than zero to scroll up/left, greater than zero for down/right.
Returns:
visibleRect.height
orvisibleRect.width
per the orientation
See Also:
Scrollable.getScrollableBlockIncrement(java.awt.Rectangle, int, int)getScrollableTracksViewportWidth
@BeanProperty(bound=false)public boolean getScrollableTracksViewportWidth()
Returns false ifautoResizeMode
is set toAUTO_RESIZE_OFF
, which indicates that the width of the viewport does not determine the width of the table. Otherwise returns true.
Specified by:
[getScrollableTracksViewportWidth](Scrollable.html#getScrollableTracksViewportWidth%28%29)
in interface[Scrollable](Scrollable.html "interface in javax.swing")
Returns:
false ifautoResizeMode
is set toAUTO_RESIZE_OFF
, otherwise returns true
See Also:
Scrollable.getScrollableTracksViewportWidth()getScrollableTracksViewportHeight
@BeanProperty(bound=false)public boolean getScrollableTracksViewportHeight()
Returnsfalse
to indicate that the height of the viewport does not determine the height of the table, unlessgetFillsViewportHeight
istrue
and the preferred height of the table is smaller than the viewport's height.
Specified by:
[getScrollableTracksViewportHeight](Scrollable.html#getScrollableTracksViewportHeight%28%29)
in interface[Scrollable](Scrollable.html "interface in javax.swing")
Returns:
false
unlessgetFillsViewportHeight
istrue
and the table needs to be stretched to fill the viewport
See Also:
Scrollable.getScrollableTracksViewportHeight(), setFillsViewportHeight(boolean), getFillsViewportHeight()setFillsViewportHeight
@BeanProperty(description="Whether or not this table is always made large enough to fill the height of an enclosing viewport")public void setFillsViewportHeight(boolean fillsViewportHeight)
Sets whether or not this table is always made large enough to fill the height of an enclosing viewport. If the preferred height of the table is smaller than the viewport, then the table will be stretched to fill the viewport. In other words, this ensures the table is never smaller than the viewport. The default for this property isfalse
.
Parameters:
fillsViewportHeight
- whether or not this table is always made large enough to fill the height of an enclosing viewport
Since:
1.6
See Also:
getFillsViewportHeight(), getScrollableTracksViewportHeight()getFillsViewportHeight
public boolean getFillsViewportHeight()
Returns whether or not this table is always made large enough to fill the height of an enclosing viewport.
Returns:
whether or not this table is always made large enough to fill the height of an enclosing viewport
Since:
1.6
See Also:
setFillsViewportHeight(boolean)createDefaultRenderers
protected void createDefaultRenderers()
Creates default cell renderers for objects, numbers, doubles, dates, booleans, and icons.
See Also:
DefaultTableCellRenderercreateDefaultEditors
protected void createDefaultEditors()
Creates default cell editors for objects, numbers, and boolean values.
See Also:
DefaultCellEditorinitializeLocalVars
protected void initializeLocalVars()
Initializes table properties to their default values.createDefaultDataModel
protected TableModel createDefaultDataModel()
Returns the default table model object, which is aDefaultTableModel
. A subclass can override this method to return a different table model object.
Returns:
the default table model object
See Also:
DefaultTableModelcreateDefaultColumnModel
Returns the default column model object, which is a
DefaultTableColumnModel
. A subclass can override this method to return a different column model object.
Returns:
the default column model object
See Also:
DefaultTableColumnModelcreateDefaultSelectionModel
Returns the default selection model object, which is a
DefaultListSelectionModel
. A subclass can override this method to return a different selection model object.
Returns:
the default selection model object
See Also:
DefaultListSelectionModelresizeAndRepaint
protected void resizeAndRepaint()
Equivalent torevalidate
followed byrepaint
.getCellEditor
Returns the active cell editor, which is
null
if the table is not currently editing.
Returns:
theTableCellEditor
that does the editing, ornull
if the table is not currently editing.
See Also:
cellEditor, getCellEditor(int, int)setCellEditor
Sets the active cell editor.
Parameters:
anEditor
- the active cell editor
See Also:
cellEditorsetEditingColumn
public void setEditingColumn(int aColumn)
Sets theeditingColumn
variable.
Parameters:
aColumn
- the column of the cell to be edited
See Also:
editingColumnsetEditingRow
public void setEditingRow(int aRow)
Sets theeditingRow
variable.
Parameters:
aRow
- the row of the cell to be edited
See Also:
editingRowgetCellRenderer
Returns an appropriate renderer for the cell specified by this row and column. If the
TableColumn
for this column has a non-null renderer, returns that. If not, finds the class of the data in this column (usinggetColumnClass
) and returns the default renderer for this type of data.
Note: Throughout the table package, the internal implementations always use this method to provide renderers so that this default behavior can be safely overridden by a subclass.
Parameters:
row
- the row of the cell to render, where 0 is the first row
column
- the column of the cell to render, where 0 is the first column
Returns:
the assigned renderer; ifnull
returns the default renderer for this type of object
See Also:
DefaultTableCellRenderer, TableColumn.setCellRenderer(javax.swing.table.TableCellRenderer), setDefaultRenderer(java.lang.Class<?>, javax.swing.table.TableCellRenderer)prepareRenderer
Prepares the renderer by querying the data model for the value and selection state of the cell at
row
,column
. Returns the component (may be aComponent
or aJComponent
) under the event location.
During a printing operation, this method will configure the renderer without indicating selection or focus, to prevent them from appearing in the printed output. To do other customizations based on whether or not the table is being printed, you can check the value ofJComponent.isPaintingForPrint(), either here or within custom renderers.
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.
Parameters:
renderer
- theTableCellRenderer
to prepare
row
- the row of the cell to render, where 0 is the first row
column
- the column of the cell to render, where 0 is the first column
Returns:
theComponent
under the event locationgetCellEditor
Returns an appropriate editor for the cell specified by
row
andcolumn
. If theTableColumn
for this column has a non-null editor, returns that. If not, finds the class of the data in this column (usinggetColumnClass
) and returns the default editor for this type of data.
Note: Throughout the table package, the internal implementations always use this method to provide editors so that this default behavior can be safely overridden by a subclass.
Parameters:
row
- the row of the cell to edit, where 0 is the first row
column
- the column of the cell to edit, where 0 is the first column
Returns:
the editor for this cell; ifnull
return the default editor for this type of cell
See Also:
DefaultCellEditorprepareEditor
Prepares the editor by querying the data model for the value and selection state of the cell at
row
,column
.
Note: Throughout the table package, the internal implementations always use this method to prepare editors so that this default behavior can be safely overridden by a subclass.
Parameters:
editor
- theTableCellEditor
to set up
row
- the row of the cell to edit, where 0 is the first row
column
- the column of the cell to edit, where 0 is the first column
Returns:
theComponent
being editedremoveEditor
public void removeEditor()
Discards the editor object and frees the real estate it used for cell rendering.paramString
protected String paramString()
Returns a string representation of this table. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not benull
.
Overrides:
[paramString](JComponent.html#paramString%28%29)
in class[JComponent](JComponent.html "class in javax.swing")
Returns:
a string representation of this tableprint
A convenience method that displays a printing dialog, and then prints this
JTable
in modePrintMode.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.
Returns:
true, unless printing is cancelled by the user
Throws:
[SecurityException](../../../java.base/java/lang/SecurityException.html "class in java.lang")
- if this thread is not allowed to initiate a print job request
[PrinterException](../../java/awt/print/PrinterException.html "class in java.awt.print")
- if an error in the print system causes the job to be aborted
Since:
1.5
See Also:
print(JTable.PrintMode, MessageFormat, MessageFormat, boolean, PrintRequestAttributeSet, boolean, PrintService), getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)print
A convenience method that displays a printing dialog, and then prints this
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.
Parameters:
printMode
- the printing mode that the printable should use
Returns:
true, unless printing is cancelled by the user
Throws:
[SecurityException](../../../java.base/java/lang/SecurityException.html "class in java.lang")
- if this thread is not allowed to initiate a print job request
[PrinterException](../../java/awt/print/PrinterException.html "class in java.awt.print")
- if an error in the print system causes the job to be aborted
Since:
1.5
See Also:
print(JTable.PrintMode, MessageFormat, MessageFormat, boolean, PrintRequestAttributeSet, boolean, PrintService), getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)print
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. 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.
Parameters:
printMode
- the printing mode that the printable should use
headerFormat
- aMessageFormat
specifying the text to be used in printing a header, or null for none
footerFormat
- aMessageFormat
specifying the text to be used in printing a footer, or null for none
Returns:
true, unless printing is cancelled by the user
Throws:
[SecurityException](../../../java.base/java/lang/SecurityException.html "class in java.lang")
- if this thread is not allowed to initiate a print job request
[PrinterException](../../java/awt/print/PrinterException.html "class in java.awt.print")
- if an error in the print system causes the job to be aborted
Since:
1.5
See Also:
print(JTable.PrintMode, MessageFormat, MessageFormat, boolean, PrintRequestAttributeSet, boolean, PrintService), getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)print
Prints this table, as specified by the fully featuredprint method, with the default printer specified as the print service.
Parameters:
printMode
- the printing mode that the printable should use
headerFormat
- aMessageFormat
specifying the text to be used in printing a header, ornull
for none
footerFormat
- aMessageFormat
specifying the text to be used in printing a footer, ornull
for none
showPrintDialog
- whether or not to display a print dialog
attr
- aPrintRequestAttributeSet
specifying any printing attributes, ornull
for none
interactive
- whether or not to print in an interactive mode
Returns:
true, unless printing is cancelled by the user
Throws:
[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")
- if the method is asked to show a printing dialog or run interactively, andGraphicsEnvironment.isHeadless
returnstrue
[SecurityException](../../../java.base/java/lang/SecurityException.html "class in java.lang")
- if this thread is not allowed to initiate a print job request
[PrinterException](../../java/awt/print/PrinterException.html "class in java.awt.print")
- if an error in the print system causes the job to be aborted
Since:
1.5
See Also:
print(JTable.PrintMode, MessageFormat, MessageFormat, boolean, PrintRequestAttributeSet, boolean, PrintService), getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat)print
Prints this
JTable
. Takes steps that the majority of developers would take in order to print aJTable
. In short, it prepares the table, callsgetPrintable
to fetch an appropriatePrintable
, and then sends it to the printer.
Aboolean
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 aPrintService
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 secondboolean
parameter allows you to specify whether or not to perform printing in an interactive mode. Iftrue
, 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 usingSwingUtilities.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.
Iffalse
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, specifyingfalse
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 aHeadlessException
.
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.
Parameters:
printMode
- the printing mode that the printable should use
headerFormat
- aMessageFormat
specifying the text to be used in printing a header, ornull
for none
footerFormat
- aMessageFormat
specifying the text to be used in printing a footer, ornull
for none
showPrintDialog
- whether or not to display a print dialog
attr
- aPrintRequestAttributeSet
specifying any printing attributes, ornull
for none
interactive
- whether or not to print in an interactive mode
service
- the destinationPrintService
, ornull
to use the default printer
Returns:
true, unless printing is cancelled by the user
Throws:
[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")
- if the method is asked to show a printing dialog or run interactively, andGraphicsEnvironment.isHeadless
returnstrue
[SecurityException](../../../java.base/java/lang/SecurityException.html "class in java.lang")
- if a security manager exists and itsSecurityManager.checkPrintJobAccess() method disallows this thread from creating a print job request
[PrinterException](../../java/awt/print/PrinterException.html "class in java.awt.print")
- if an error in the print system causes the job to be aborted
Since:
1.6
See Also:
getPrintable(javax.swing.JTable.PrintMode, java.text.MessageFormat, java.text.MessageFormat), GraphicsEnvironment.isHeadless()getPrintable
Return a
Printable
for use in printing this JTable.
This method is meant for those wishing to customize the defaultPrintable
implementation used byJTable
'sprint
methods. Developers wanting simply to print the table should use one of those methods directly.
ThePrintable
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'sComponentOrientation
.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.
ThePrintable
heads the portion of table on each page with the appropriate section from the table'sJTableHeader
, if it has one.
Header and footer text can be added to the output by providingMessageFormat
arguments. The printing code requests Strings from the formats, providing a single item which may be included in the formatted string: anInteger
representing the current page number.
You are encouraged to read the documentation forMessageFormat
as some characters, such as single-quote, are special and need to be escaped.
Here's an example of creating aMessageFormat
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:
* In any mode, when the header or footer text is too wide to fit completely in the printable area -- print as much of the text as possible starting from the beginning, as determined by the table'sComponentOrientation
.
* In any mode, when a row is too tall to fit in the printable area -- print the upper-most portion of the row and paint no lower border on the table.
* InPrintMode.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.
It is entirely valid for thisPrintable
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 withPrintMode.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 thisPrintable
has been fetched (invalid modifications include changes in size or underlying data). The behavior of the returnedPrintable
is undefined once the table has been changed.
Parameters:
printMode
- the printing mode that the printable should use
headerFormat
- aMessageFormat
specifying the text to be used in printing a header, or null for none
footerFormat
- aMessageFormat
specifying the text to be used in printing a footer, or null for none
Returns:
aPrintable
for printing this JTable
Since:
1.5
See Also:
print(JTable.PrintMode, MessageFormat, MessageFormat, boolean, PrintRequestAttributeSet, boolean), Printable, PrinterJobgetAccessibleContext
Gets the AccessibleContext associated with this JTable. For tables, the AccessibleContext takes the form of an AccessibleJTable. A new AccessibleJTable instance is created if necessary.
Specified by:
[getAccessibleContext](../accessibility/Accessible.html#getAccessibleContext%28%29)
in interface[Accessible](../accessibility/Accessible.html "interface in javax.accessibility")
Overrides:
[getAccessibleContext](../../java/awt/Component.html#getAccessibleContext%28%29)
in class[Component](../../java/awt/Component.html "class in java.awt")
Returns:
an AccessibleJTable that serves as the AccessibleContext of this JTable