src/java.desktop/share/classes/javax/swing/JTable.java
Print this page
@@ -20,21 +20,23 @@
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-
package javax.swing;
import java.util.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
-import java.beans.*;
+import java.beans.JavaBean;
+import java.beans.BeanProperty;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.io.InvalidObjectException;
@@ -205,24 +207,21 @@
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
- *
- * @beaninfo
- * attribute: isContainer false
- * description: A component which displays data in a two dimensional grid.
- *
* @author Philip Milne
* @author Shannon Hickey (printing support)
* @see javax.swing.table.DefaultTableModel
* @see javax.swing.table.TableRowSorter
* @since 1.2
*/
/* The first versions of the JTable, contained in Swing-0.1 through
* Swing-0.4, were written by Alan Chung.
*/
+@JavaBean(defaultProperty = "UI", description = "A component which displays data in a two dimensional grid.")
+@SwingContainer(false)
@SuppressWarnings("serial") // Same-version serialization only
public class JTable extends JComponent implements TableModelListener, Scrollable,
TableColumnModelListener, ListSelectionListener, CellEditorListener,
Accessible, RowSorterListener
{
@@ -892,14 +891,13 @@
* Sets the <code>tableHeader</code> working with this <code>JTable</code> to <code>newHeader</code>.
* It is legal to have a <code>null</code> <code>tableHeader</code>.
*
* @param tableHeader new tableHeader
* @see #getTableHeader
- * @beaninfo
- * bound: true
- * description: The JTableHeader instance which renders the column headers.
*/
+ @BeanProperty(description
+ = "The JTableHeader instance which renders the column headers.")
public void setTableHeader(JTableHeader tableHeader) {
if (this.tableHeader != tableHeader) {
JTableHeader old = this.tableHeader;
// Release the old header
if (old != null) {
@@ -931,14 +929,13 @@
*
* @param rowHeight new row height
* @exception IllegalArgumentException if <code>rowHeight</code> is
* less than 1
* @see #getRowHeight
- * @beaninfo
- * bound: true
- * description: The height of the specified row.
*/
+ @BeanProperty(description
+ = "The height of the specified row.")
public void setRowHeight(int rowHeight) {
if (rowHeight <= 0) {
throw new IllegalArgumentException("New row height less than 1");
}
int old = this.rowHeight;
@@ -977,15 +974,14 @@
* @param row the row whose height is being
changed
* @param rowHeight new row height, in pixels
* @exception IllegalArgumentException if <code>rowHeight</code> is
* less than 1
- * @beaninfo
- * bound: true
- * description: The height in pixels of the cells in <code>row</code>
* @since 1.3
*/
+ @BeanProperty(description
+ = "The height in pixels of the cells in <code>row</code>")
public void setRowHeight(int row, int rowHeight) {
if (rowHeight <= 0) {
throw new IllegalArgumentException("New row height less than 1");
}
getRowModel().setSize(row, rowHeight);
@@ -1008,14 +1004,13 @@
/**
* Sets the amount of empty space between cells in adjacent rows.
*
* @param rowMargin the number of pixels between cells in a row
* @see #getRowMargin
- * @beaninfo
- * bound: true
- * description: The amount of space between cells.
*/
+ @BeanProperty(description
+ = "The amount of space between cells.")
public void setRowMargin(int rowMargin) {
int old = this.rowMargin;
this.rowMargin = rowMargin;
resizeAndRepaint();
firePropertyChange("rowMargin", old, rowMargin);
@@ -1039,14 +1034,13 @@
*
* @param intercellSpacing a <code>Dimension</code>
* specifying the new width
* and height between cells
* @see #getIntercellSpacing
- * @beaninfo
- * description: The spacing between the cells,
- * drawn in the background color of the JTable.
*/
+ @BeanProperty(bound = false, description
+ = "The spacing between the cells, drawn in the background color of the JTable.")
public void setIntercellSpacing(Dimension intercellSpacing) {
// Set the rowMargin here and columnMargin in the TableColumnModel
setRowMargin(intercellSpacing.height);
getColumnModel().setColumnMargin(intercellSpacing.width);
@@ -1069,14 +1063,13 @@
* The default color is look and feel dependent.
*
* @param gridColor the new color of the grid lines
* @exception IllegalArgumentException if <code>gridColor</code> is <code>null</code>
* @see #getGridColor
- * @beaninfo
- * bound: true
- * description: The grid color.
*/
+ @BeanProperty(description
+ = "The grid color.")
public void setGridColor(Color gridColor) {
if (gridColor == null) {
throw new IllegalArgumentException("New color is null");
}
Color old = this.gridColor;
@@ -1106,13 +1099,13 @@
*
* @param showGrid true if table view should draw grid lines
*
* @see #setShowVerticalLines
* @see #setShowHorizontalLines
- * @beaninfo
- * description: The color used to draw the grid lines.
*/
+ @BeanProperty(description
+ = "The color used to draw the grid lines.")
public void setShowGrid(boolean showGrid) {
setShowHorizontalLines(showGrid);
setShowVerticalLines(showGrid);
// Redraw
@@ -1125,14 +1118,13 @@
*
* @param showHorizontalLines true if table view should draw horizontal lines
* @see #getShowHorizontalLines
* @see #setShowGrid
* @see #setShowVerticalLines
- * @beaninfo
- * bound: true
- * description: Whether horizontal lines should be drawn in between the cells.
*/
+ @BeanProperty(description
+ = "Whether horizontal lines should be drawn in between the cells.")
public void setShowHorizontalLines(boolean showHorizontalLines) {
boolean old = this.showHorizontalLines;
this.showHorizontalLines = showHorizontalLines;
firePropertyChange("showHorizontalLines", old, showHorizontalLines);
@@ -1146,14 +1138,13 @@
*
* @param showVerticalLines true if table view should draw vertical lines
* @see #getShowVerticalLines
* @see #setShowGrid
* @see #setShowHorizontalLines
- * @beaninfo
- * bound: true
- * description: Whether vertical lines should be drawn in between the cells.
*/
+ @BeanProperty(description
+ = "Whether vertical lines should be drawn in between the cells.")
public void setShowVerticalLines(boolean showVerticalLines) {
boolean old = this.showVerticalLines;
this.showVerticalLines = showVerticalLines;
firePropertyChange("showVerticalLines", old, showVerticalLines);
// Redraw
@@ -1196,19 +1187,18 @@
* AUTO_RESIZE_LAST_COLUMN,
* AUTO_RESIZE_ALL_COLUMNS
*
* @see #getAutoResizeMode
* @see #doLayout
- * @beaninfo
- * bound: true
- * description: Whether the columns should adjust themselves automatically.
- * enum: AUTO_RESIZE_OFF JTable.AUTO_RESIZE_OFF
- * AUTO_RESIZE_NEXT_COLUMN JTable.AUTO_RESIZE_NEXT_COLUMN
- * AUTO_RESIZE_SUBSEQUENT_COLUMNS JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
- * AUTO_RESIZE_LAST_COLUMN JTable.AUTO_RESIZE_LAST_COLUMN
- * AUTO_RESIZE_ALL_COLUMNS JTable.AUTO_RESIZE_ALL_COLUMNS
*/
+ @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) {
if (isValidAutoResizeMode(mode)) {
int old = autoResizeMode;
autoResizeMode = mode;
resizeAndRepaint();
@@ -1246,14 +1236,13 @@
* <code>autoCreateColumnsFromModel</code> changes from false to true.
*
* @param autoCreateColumnsFromModel true if <code>JTable</code> should automatically create columns
* @see #getAutoCreateColumnsFromModel
* @see #createDefaultColumnsFromModel
- * @beaninfo
- * bound: true
- * description: Automatically populates the columnModel when a new TableModel is submitted.
*/
+ @BeanProperty(description
+ = "Automatically populates the columnModel when a new TableModel is submitted.")
public void setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel) {
if (this.autoCreateColumnsFromModel != autoCreateColumnsFromModel) {
boolean old = this.autoCreateColumnsFromModel;
this.autoCreateColumnsFromModel = autoCreateColumnsFromModel;
if (autoCreateColumnsFromModel) {
@@ -1440,15 +1429,13 @@
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #getDragEnabled
* @see #setTransferHandler
* @see TransferHandler
* @since 1.4
- *
- * @beaninfo
- * description: determines whether automatic drag handling is enabled
- * bound: false
*/
+ @BeanProperty(bound = false, description
+ = "determines whether automatic drag handling is enabled")
public void setDragEnabled(boolean b) {
checkDragEnabled(b);
dragEnabled = b;
}
@@ -1832,10 +1819,11 @@
* @return the drop location
* @see #setDropMode
* @see TransferHandler#canImport(TransferHandler.TransferSupport)
* @since 1.6
*/
+ @BeanProperty(bound = false)
public final DropLocation getDropLocation() {
return dropLocation;
}
/**
@@ -1851,16 +1839,14 @@
* property is {@code false}.
*
* @param autoCreateRowSorter whether or not a {@code RowSorter}
* should be automatically created
* @see javax.swing.table.TableRowSorter
- * @beaninfo
- * bound: true
- * preferred: true
- * description: Whether or not to turn on sorting by default.
* @since 1.6
*/
+ @BeanProperty(preferred = true, description
+ = "Whether or not to turn on sorting by default.")
public void setAutoCreateRowSorter(boolean autoCreateRowSorter) {
boolean oldValue = this.autoCreateRowSorter;
this.autoCreateRowSorter = autoCreateRowSorter;
if (autoCreateRowSorter) {
setRowSorter(new TableRowSorter<TableModel>(getModel()));
@@ -1887,16 +1873,14 @@
* If true, on sorting the selection is reset such that
* the same rows, in terms of the model, remain selected. The default
* is true.
*
* @param update whether or not to update the selection on sorting
- * @beaninfo
- * bound: true
- * expert: true
- * description: Whether or not to update the selection on sorting
* @since 1.6
*/
+ @BeanProperty(expert = true, description
+ = "Whether or not to update the selection on sorting")
public void setUpdateSelectionOnSort(boolean update) {
if (updateSelectionOnSort != update) {
updateSelectionOnSort = update;
firePropertyChange("updateSelectionOnSort", !update, update);
}
@@ -1927,15 +1911,14 @@
* that of this <code>JTable</code> undefined behavior will result.
*
* @param sorter the <code>RowSorter</code>; <code>null</code> turns
* sorting off
* @see javax.swing.table.TableRowSorter
- * @beaninfo
- * bound: true
- * description: The table's RowSorter
* @since 1.6
*/
+ @BeanProperty(description
+ = "The table's RowSorter")
public void setRowSorter(RowSorter<? extends TableModel> sorter) {
RowSorter<? extends TableModel> oldRowSorter = null;
if (sortManager != null) {
oldRowSorter = sortManager.sorter;
sortManager.dispose();
@@ -1983,16 +1966,16 @@
* <code>JList</code>. See the <code>setSelectionMode</code> method
* in <code>JList</code> for details about the modes.
*
* @param selectionMode the mode used by the row and column selection models
* @see JList#setSelectionMode
- * @beaninfo
- * description: The selection mode used by the row and column selection models.
- * enum: SINGLE_SELECTION ListSelectionModel.SINGLE_SELECTION
- * SINGLE_INTERVAL_SELECTION ListSelectionModel.SINGLE_INTERVAL_SELECTION
- * MULTIPLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
*/
+ @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) {
clearSelection();
getSelectionModel().setSelectionMode(selectionMode);
getColumnModel().getSelectionModel().setSelectionMode(selectionMode);
}
@@ -2000,15 +1983,13 @@
/**
* Sets whether the rows in this model can be selected.
*
* @param rowSelectionAllowed true if this model will allow row selection
* @see #getRowSelectionAllowed
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: If true, an entire row is selected for each selected cell.
*/
+ @BeanProperty(visualUpdate = true, description
+ = "If true, an entire row is selected for each selected cell.")
public void setRowSelectionAllowed(boolean rowSelectionAllowed) {
boolean old = this.rowSelectionAllowed;
this.rowSelectionAllowed = rowSelectionAllowed;
if (old != rowSelectionAllowed) {
repaint();
@@ -2029,15 +2010,13 @@
/**
* Sets whether the columns in this model can be selected.
*
* @param columnSelectionAllowed true if this model will allow column selection
* @see #getColumnSelectionAllowed
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: If true, an entire column is selected for each selected cell.
*/
+ @BeanProperty(visualUpdate = true, description
+ = "If true, an entire column is selected for each selected cell.")
public void setColumnSelectionAllowed(boolean columnSelectionAllowed) {
boolean old = columnModel.getColumnSelectionAllowed();
columnModel.setColumnSelectionAllowed(columnSelectionAllowed);
if (old != columnSelectionAllowed) {
repaint();
@@ -2067,16 +2046,13 @@
*
* @param cellSelectionEnabled true if simultaneous row and column
* selection is allowed
* @see #getCellSelectionEnabled
* @see #isCellSelected
- * @beaninfo
- * bound: true
- * attribute: visualUpdate true
- * description: Select a rectangular region of cells rather than
- * rows or columns.
*/
+ @BeanProperty(visualUpdate = true, description
+ = "Select a rectangular region of cells rather than rows or columns.")
public void setCellSelectionEnabled(boolean cellSelectionEnabled) {
setRowSelectionAllowed(cellSelectionEnabled);
setColumnSelectionAllowed(cellSelectionEnabled);
boolean old = this.cellSelectionEnabled;
this.cellSelectionEnabled = cellSelectionEnabled;
@@ -2260,19 +2236,21 @@
/**
* Returns the index of the first selected row, -1 if no row is selected.
* @return the index of the first selected row
*/
+ @BeanProperty(bound = false)
public int getSelectedRow() {
return selectionModel.getMinSelectionIndex();
}
/**
* Returns the index of the first selected column,
* -1 if no column is selected.
* @return the index of the first selected column
*/
+ @BeanProperty(bound = false)
public int getSelectedColumn() {
return columnModel.getSelectionModel().getMinSelectionIndex();
}
/**
@@ -2280,10 +2258,11 @@
*
* @return an array of integers containing the indices of all selected rows,
* or an empty array if no row is selected
* @see #getSelectedRow
*/
+ @BeanProperty(bound = false)
public int[] getSelectedRows() {
int iMin = selectionModel.getMinSelectionIndex();
int iMax = selectionModel.getMaxSelectionIndex();
if ((iMin == -1) || (iMax == -1)) {
@@ -2307,19 +2286,21 @@
*
* @return an array of integers containing the indices of all selected columns,
* or an empty array if no column is selected
* @see #getSelectedColumn
*/
+ @BeanProperty(bound = false)
public int[] getSelectedColumns() {
return columnModel.getSelectedColumns();
}
/**
* Returns the number of selected rows.
*
* @return the number of selected rows, 0 if no rows are selected
*/
+ @BeanProperty(bound = false)
public int getSelectedRowCount() {
int iMin = selectionModel.getMinSelectionIndex();
int iMax = selectionModel.getMaxSelectionIndex();
int count = 0;
@@ -2334,10 +2315,11 @@
/**
* Returns the number of selected columns.
*
* @return the number of selected columns, 0 if no columns are selected
*/
+ @BeanProperty(bound = false)
public int getSelectedColumnCount() {
return columnModel.getSelectedColumnCount();
}
/**
@@ -2521,14 +2503,13 @@
* @see #getSelectionForeground
* @see #setSelectionBackground
* @see #setForeground
* @see #setBackground
* @see #setFont
- * @beaninfo
- * bound: true
- * description: A default foreground color for selected cells.
*/
+ @BeanProperty(description
+ = "A default foreground color for selected cells.")
public void setSelectionForeground(Color selectionForeground) {
Color old = this.selectionForeground;
this.selectionForeground = selectionForeground;
firePropertyChange("selectionForeground", old, selectionForeground);
repaint();
@@ -2559,14 +2540,13 @@
* @see #getSelectionBackground
* @see #setSelectionForeground
* @see #setForeground
* @see #setBackground
* @see #setFont
- * @beaninfo
- * bound: true
- * description: A default background color for selected cells.
*/
+ @BeanProperty(description
+ = "A default background color for selected cells.")
public void setSelectionBackground(Color selectionBackground) {
Color old = this.selectionBackground;
this.selectionBackground = selectionBackground;
firePropertyChange("selectionBackground", old, selectionBackground);
repaint();
@@ -2678,10 +2658,11 @@
* <code>TableModel</code>.
*
* @return the number of rows shown in the <code>JTable</code>
* @see #getColumnCount
*/
+ @BeanProperty(bound = false)
public int getRowCount() {
RowSorter<?> sorter = getRowSorter();
if (sorter != null) {
return sorter.getViewRowCount();
}
@@ -2694,10 +2675,11 @@
*
* @return the number of columns in the table
* @see #getRowCount
* @see #removeColumn
*/
+ @BeanProperty(bound = false)
public int getColumnCount() {
return getColumnModel().getColumnCount();
}
/**
@@ -3562,20 +3544,22 @@
*
* @return true if the table is editing a cell
* @see #editingColumn
* @see #editingRow
*/
+ @BeanProperty(bound = false)
public boolean isEditing() {
return cellEditor != null;
}
/**
* Returns the component that is handling the editing session.
* If nothing is being edited, returns null.
*
* @return Component handling editing session
*/
+ @BeanProperty(bound = false)
public Component getEditorComponent() {
return editorComp;
}
/**
@@ -3618,16 +3602,13 @@
/**
* Sets the L&F object that renders this component and repaints.
*
* @param ui the TableUI L&F object
* @see UIDefaults#getUI
- * @beaninfo
- * bound: true
- * hidden: true
- * attribute: visualUpdate true
- * description: The UI object that implements the Component's LookAndFeel.
*/
+ @BeanProperty(hidden = true, visualUpdate = true, description
+ = "The UI object that implements the Component's LookAndFeel.")
public void setUI(TableUI ui) {
if (this.ui != ui) {
super.setUI(ui);
repaint();
}
@@ -3679,10 +3660,11 @@
*
* @return the string "TableUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
+ @BeanProperty(bound = false)
public String getUIClassID() {
return uiClassID;
}
@@ -3695,14 +3677,13 @@
* with it for listener notifications from the new data model.
*
* @param dataModel the new data source for this table
* @throws IllegalArgumentException if {@code dataModel} is {@code null}
* @see #getModel
- * @beaninfo
- * bound: true
- * description: The model that is the source of the data for this view.
*/
+ @BeanProperty(description
+ = "The model that is the source of the data for this view.")
public void setModel(final TableModel dataModel) {
if (dataModel == null) {
throw new IllegalArgumentException("Cannot set a null TableModel");
}
if (this.dataModel != dataModel) {
@@ -3741,14 +3722,13 @@
* column model of the {@code JTableHeader} to {@code columnModel}.
*
* @param columnModel the new data source for this table
* @throws IllegalArgumentException if {@code columnModel} is {@code null}
* @see #getColumnModel
- * @beaninfo
- * bound: true
- * description: The object governing the way columns appear in the view.
*/
+ @BeanProperty(description
+ = "The object governing the way columns appear in the view.")
public void setColumnModel(final TableColumnModel columnModel) {
if (columnModel == null) {
throw new IllegalArgumentException("Cannot set a null ColumnModel");
}
TableColumnModel old = this.columnModel;
@@ -3786,14 +3766,13 @@
*
* @param selectionModel the new selection model
* @throws IllegalArgumentException if {@code selectionModel} is
* {@code null}
* @see #getSelectionModel
- * @beaninfo
- * bound: true
- * description: The selection model for rows.
*/
+ @BeanProperty(description
+ = "The selection model for rows.")
public void setSelectionModel(final ListSelectionModel selectionModel) {
if (selectionModel == null) {
throw new IllegalArgumentException("Cannot set a null SelectionModel");
}
@@ -4782,13 +4761,13 @@
* Sets the preferred size of the viewport for this table.
*
* @param size a <code>Dimension</code> object specifying the <code>preferredSize</code> of a
* <code>JViewport</code> whose view is this table
* @see Scrollable#getPreferredScrollableViewportSize
- * @beaninfo
- * description: The preferred size of the viewport.
*/
+ @BeanProperty(bound = false, description
+ = "The preferred size of the viewport.")
public void setPreferredScrollableViewportSize(Dimension size) {
preferredViewportSize = size;
}
/**
@@ -5220,10 +5199,11 @@
*
* @return false if <code>autoResizeMode</code> is set
* to <code>AUTO_RESIZE_OFF</code>, otherwise returns true
* @see Scrollable#getScrollableTracksViewportWidth
*/
+ @BeanProperty(bound = false)
public boolean getScrollableTracksViewportWidth() {
return !(autoResizeMode == AUTO_RESIZE_OFF);
}
/**
@@ -5237,10 +5217,11 @@
* the viewport
* @see Scrollable#getScrollableTracksViewportHeight
* @see #setFillsViewportHeight
* @see #getFillsViewportHeight
*/
+ @BeanProperty(bound = false)
public boolean getScrollableTracksViewportHeight() {
Container parent = SwingUtilities.getUnwrappedParent(this);
return getFillsViewportHeight()
&& parent instanceof JViewport
&& parent.getHeight() > getPreferredSize().height;
@@ -5258,15 +5239,13 @@
* made large enough to fill the height of an enclosing
* viewport
* @see #getFillsViewportHeight
* @see #getScrollableTracksViewportHeight
* @since 1.6
- * @beaninfo
- * bound: true
- * description: Whether or not this table is always made large enough
- * to fill the height of an enclosing viewport
*/
+ @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) {
boolean old = this.fillsViewportHeight;
this.fillsViewportHeight = fillsViewportHeight;
resizeAndRepaint();
firePropertyChange("fillsViewportHeight", old, fillsViewportHeight);
@@ -5659,14 +5638,13 @@
/**
* Sets the active cell editor.
*
* @param anEditor the active cell editor
* @see #cellEditor
- * @beaninfo
- * bound: true
- * description: The table's active cell editor.
*/
+ @BeanProperty(description
+ = "The table's active cell editor.")
public void setCellEditor(TableCellEditor anEditor) {
TableCellEditor oldEditor = cellEditor;
cellEditor = anEditor;
firePropertyChange("tableCellEditor", oldEditor, anEditor);
}
@@ -6654,10 +6632,11 @@
* A new AccessibleJTable instance is created if necessary.
*
* @return an AccessibleJTable that serves as the
* AccessibleContext of this JTable
*/
+ @BeanProperty(bound = false)
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJTable();
}
return accessibleContext;