- /*
- * @(#)JTable.java 1.168 01/02/09
- *
- * Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved.
- *
- * This software is the proprietary information of Sun Microsystems, Inc.
- * Use is subject to license terms.
- *
- */
- package javax.swing;
- import java.util.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.beans.*;
- import java.io.Serializable;
- import java.io.ObjectOutputStream;
- import java.io.ObjectInputStream;
- import java.io.IOException;
- import javax.accessibility.*;
- import javax.swing.event.*;
- import javax.swing.plaf.*;
- import javax.swing.table.*;
- import javax.swing.border.*;
- import java.text.NumberFormat;
- import java.text.DateFormat;
- /**
- * <code>JTable</code> is a user-interface component that presents data in
- * a two-dimensional table format.
- * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html">How to Use Tables</a>
- * in <em>The Java Tutorial</em>
- * for task-oriented documentation and examples of using <code>JTable</code>.
- *
- * <p>
- * The <code>JTable</code> 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:
- * <p>
- * <pre>
- * TableModel dataModel = new AbstractTableModel() {
- * public int getColumnCount() { return 10; }
- * public int getRowCount() { return 10;}
- * public Object getValueAt(int row, int col) { return new Integer(row*col); }
- * };
- * JTable table = new JTable(dataModel);
- * JScrollPane scrollpane = new JScrollPane(table);
- * </pre>
- * <p>
- * Because the <code>JTable</code> is now much easier to set up with custom models
- * the <code>DefaultTableModel</code> is less useful than it was in previous releases.
- * Instead of copying the data in an application into the <code>DefaultTableModel</code>,
- * we recommend wrapping it in the methods of the <code>TableModel</code> interface and
- * passing the real data to the <code>JTable</code> as above. This technique is nearly as concise
- * as using a <code>DefaultTableModel</code> and starting this way has a number of advantages
- * over the longer term. In particular: it is a scalable technique,
- * can more easily handle dynamic or editable tables, and often results in much
- * more efficient applications because the model is free to choose the
- * internal representation that best suits the data.
- * <p>
- * The "Table" directory in the examples/demo area gives a number of complete
- * examples of <code>JTable</code> usage, covering how the <code>JTable</code> 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. For example, overriding
- * <code>AbstractTableModel</code>'s <code>getColumnClass</code> method to return a value of
- * <code>ImageIcon.class</code> for a given column allows icons to be displayed,
- * while returning a value of <code>Number.class</code> allows digits to be
- * right-justified in the column.
- * <p>
- * The <code>JTable</code> uses integers exclusively to refer to both the rows and the columns
- * of the model that it displays. The <code>JTable</code> simply takes a tabular range of cells
- * and uses <code>getValueAt(int, int)</code> to retrieve and display the appropriate
- * values from the model.
- * <p>
- * If <code>getTableHeader().setReorderingAllowed(boolean)</code> is used to
- * enable column reordering columns may be rearranged in the <code>JTable</code> 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 <code>JTable</code> maintains the new order of the columns
- * internally and converts its column indices before querying the model.
- * <p>
- * So, when writing a <code>TableModel</code>, 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.
- * <p>
- * The general rule for the <code>JTable</code> API and the APIs of all its associated classes,
- * including the column model and both the row and column selection models, is:
- * methods using integer indices for rows and columns always use the coordinate
- * system of the view. There are three exceptions to this rule:
- * <ul>
- * <li> All references to rows and columns in the <code>TableModel</code>
- * interface are in the coordinate system of the model.
- * <li> The index <code>modelIndex</code> in the <code>TableColumn</code> constructors
- * refers to the index of the column in the model, not the view.
- * <li> All constructors for the <code>TableModelEvent</code>, which describes changes
- * that have taken place in a table model, use the coordinate system
- * of the model.
- * </ul>
- * The <code>TableColumn</code> provides a slot for holding an identifier or "tag" for each column,
- * and the <code>JTable</code> and <code>TableColumnModel</code> both support <code>getColumn(Object id)</code>
- * conveniences for locating columns by their identifier. If no identifier is
- * explicitly set, the <code>TableColumn</code> returns its header value (the name of the column)
- * as a default. A different identifier, which can be of any type, can be set
- * using the <code>TableColumn</code>'s <code>setIdentifier</code> method. All of the <code>JTable</code>'s
- * functions operate correctly regardless of the type and uniqueness of these
- * identifiers.
- * <p>
- * The <code>convertColumnIndexToView</code> and
- * <code>convertColumnIndexToModel</code> methods have been provided to
- * convert between the two coordinate systems but
- * they are rarely needed during normal use.
- * <p>
- * As for all <code>JComponent</code> classes, you can use
- * {@link InputMap} and {@link ActionMap} to associate an
- * {@link Action} object with a {@link KeyStroke} and execute the
- * action under specified conditions.
- * <p>
- * For the keyboard keys used by this component in the standard Look and
- * Feel (L&F) renditions, see the
- * <a href="doc-files/Key-Index.html#JTable"><code>JTable</code></a> key assignments.
- * <p>
- * <strong>Warning:</strong>
- * 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. A future release of Swing will provide support for
- * long term persistence.
- *
- *
- * @beaninfo
- * attribute: isContainer false
- * description: A component which displays data in a two dimensional grid.
- *
- * @version 1.168 02/09/01
- * @author Philip Milne
- */
- /* The first versions of the JTable, contained in Swing-0.1 through
- * Swing-0.4, were written by Alan Chung.
- */
- public class JTable extends JComponent implements TableModelListener, Scrollable,
- TableColumnModelListener, ListSelectionListener, CellEditorListener,
- Accessible
- {
- //
- // Static Constants
- //
- /**
- * @see #getUIClassID
- * @see #readObject
- */
- private static final String uiClassID = "TableUI";
- /** Do not adjust column widths automatically; use a scrollbar. */
- public static final int AUTO_RESIZE_OFF = 0;
- /** When a column is adjusted in the UI, adjust the next column the opposite way. */
- public static final int AUTO_RESIZE_NEXT_COLUMN = 1;
- /** During UI adjustment, change subsequent columns to preserve the total width;
- * this is the default behavior. */
- public static final int AUTO_RESIZE_SUBSEQUENT_COLUMNS = 2;
- /** During all resize operations, apply adjustments to the last column only. */
- public static final int AUTO_RESIZE_LAST_COLUMN = 3;
- /** During all resize operations, proportionately resize all columns. */
- public static final int AUTO_RESIZE_ALL_COLUMNS = 4;
- //
- // Instance Variables
- //
- /** The <code>TableModel</code> of the table. */
- protected TableModel dataModel;
- /** The <code>TableColumnModel</code> of the table. */
- protected TableColumnModel columnModel;
- /** The <code>ListSelectionModel</code> of the table, used to keep track of row selections. */
- protected ListSelectionModel selectionModel;
- /** The <code>TableHeader</code> working with the table. */
- protected JTableHeader tableHeader;
- /** The height in pixels of each row in the table. */
- protected int rowHeight;
- /** The height in pixels of the margin between the cells in each row. */
- protected int rowMargin;
- /** The color of the grid. */
- protected Color gridColor;
- /** The table draws horizontal lines between cells if <code>showHorizontalLines</code> is true. */
- protected boolean showHorizontalLines;
- /** The table draws vertical lines between cells if <code>showVerticalLines</code> is true. */
- protected boolean showVerticalLines;
- /**
- * 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 int autoResizeMode;
- /**
- * The table will query the <code>TableModel</code> to build the default
- * set of columns if this is true.
- */
- protected boolean autoCreateColumnsFromModel;
- /** Used by the <code>Scrollable</code> interface to determine the initial visible area. */
- protected Dimension preferredViewportSize;
- /** True if row selection is allowed in this table. */
- protected boolean rowSelectionAllowed;
- /**
- * Obsolete as of Java 2 platform v1.3. Please use the
- * <code>rowSelectionAllowed</code> property and the
- * <code>columnSelectionAllowed</code> property of the
- * <code>columnModel</code> instead. Or use the
- * method <code>getCellSelectionEnabled</code>.
- */
- /*
- * If true, both a row selection and a column selection
- * can be non-empty at the same time, the selected cells are the
- * the cells whose row and column are both selected.
- */
- protected boolean cellSelectionEnabled;
- /** If editing, the <code>Component</code> that is handling the editing. */
- transient protected Component editorComp;
- /**
- * The object that overwrites the screen real estate occupied by the
- * current cell and allows the user to change its contents.
- */
- transient protected TableCellEditor cellEditor;
- /** Identifies the column of the cell being edited. */
- transient protected int editingColumn;
- /** Identifies the row of the cell being edited. */
- transient protected int editingRow;
- /**
- * A table of objects that display the contents of a cell,
- * indexed by class as declared in <code>getColumnClass</code>
- * in the <code>TableModel</code> interface.
- */
- transient protected Hashtable defaultRenderersByColumnClass;
- /**
- * A table of objects that display and edit the contents of a cell,
- * indexed by class as declared in <code>getColumnClass</code>
- * in the <code>TableModel</code> interface.
- */
- transient protected Hashtable defaultEditorsByColumnClass;
- /** The foreground color of selected cells. */
- protected Color selectionForeground;
- /** The background color of selected cells. */
- protected Color selectionBackground;
- //
- // Private state
- //
- private boolean reentrantCall = false;
- private SizeSequence rowModel;
- //
- // Constructors
- //
- /**
- * Constructs a default <code>JTable</code> that is initialized with a default
- * data model, a default column model, and a default selection
- * model.
- *
- * @see #createDefaultDataModel
- * @see #createDefaultColumnModel
- * @see #createDefaultSelectionModel
- */
- public JTable() {
- this(null, null, null);
- }
- /**
- * Constructs a <code>JTable</code> that is initialized with
- * <code>dm</code> as the data model, a default column model,
- * and a default selection model.
- *
- * @param dm the data model for the table
- * @see #createDefaultColumnModel
- * @see #createDefaultSelectionModel
- */
- public JTable(TableModel dm) {
- this(dm, null, null);
- }
- /**
- * Constructs a <code>JTable</code> that is initialized with
- * <code>dm</code> as the data model, <code>cm</code>
- * as the column model, and a default selection model.
- *
- * @param dm the data model for the table
- * @param cm the column model for the table
- * @see #createDefaultSelectionModel
- */
- public JTable(TableModel dm, TableColumnModel cm) {
- this(dm, cm, null);
- }
- /**
- * Constructs a <code>JTable</code> that is initialized with
- * <code>dm</code> as the data model, <code>cm</code> as the
- * column model, and <code>sm</code> as the selection model.
- * If any of the parameters are <code>null</code> this method
- * will initialize the table with the corresponding default model.
- * The <code>autoCreateColumnsFromModel</code> flag is set to false
- * if <code>cm</code> is non-null, otherwise it is set to true
- * and the column model is populated with suitable
- * <code>TableColumns</code> for the columns in <code>dm</code>.
- *
- * @param dm the data model for the table
- * @param cm the column model for the table
- * @param sm the row selection model for the table
- * @see #createDefaultDataModel
- * @see #createDefaultColumnModel
- * @see #createDefaultSelectionModel
- */
- public JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
- super();
- setLayout(null);
- if (cm == null) {
- cm = createDefaultColumnModel();
- autoCreateColumnsFromModel = true;
- }
- setColumnModel(cm);
- if (sm == null) {
- sm = createDefaultSelectionModel();
- }
- setSelectionModel(sm);
- // Set the model last, that way if the autoCreatColumnsFromModel has
- // been set above, we will automatically populate an empty columnModel
- // with suitable columns for the new model.
- if (dm == null) {
- dm = createDefaultDataModel();
- }
- setModel(dm);
- initializeLocalVars();
- updateUI();
- }
- /**
- * Constructs a <code>JTable</code> with <code>numRows</code>
- * and <code>numColumns</code> of empty cells using
- * <code>DefaultTableModel</code>. The columns will have
- * names of the form "A", "B", "C", etc.
- *
- * @param numRows the number of rows the table holds
- * @param numColumns the number of columns the table holds
- * @see javax.swing.table.DefaultTableModel
- */
- public JTable(int numRows, int numColumns) {
- this(new DefaultTableModel(numRows, numColumns));
- }
- /**
- * Constructs a <code>JTable</code> to display the values in the
- * <code>Vector</code> of <code>Vectors</code>, <code>rowData</code>,
- * with column names, <code>columnNames</code>. The
- * <code>Vectors</code> contained in <code>rowData</code>
- * 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:
- * <p>
- * <pre>((Vector)rowData.elementAt(1)).elementAt(5);</pre>
- * <p>
- * Each row must contain a value for each column or an exception
- * will be raised.
- * <p>
- * @param rowData the data for the new table
- * @param columnNames names of each column
- */
- public JTable(final Vector rowData, final Vector columnNames) {
- this(new AbstractTableModel() {
- public String getColumnName(int column) { return columnNames.elementAt(column).toString(); }
- public int getRowCount() { return rowData.size(); }
- public int getColumnCount() { return columnNames.size(); }
- public Object getValueAt(int row, int column) {
- return ((Vector)rowData.elementAt(row)).elementAt(column);
- }
- public boolean isCellEditable(int row, int column) { return true; }
- public void setValueAt(Object value, int row, int column) {
- ((Vector)rowData.elementAt(row)).setElementAt(value, column);
- fireTableCellUpdated(row, column);
- }
- });
- }
- /**
- * Constructs a <code>JTable</code> to display the values in the two dimensional array,
- * <code>rowData</code>, with column names, <code>columnNames</code>.
- * <code>rowData</code> is an array of rows, so the value of the cell at row 1,
- * column 5 can be obtained with the following code:
- * <p>
- * <pre> rowData[1][5]; </pre>
- * <p>
- * All rows must be of the same length as <code>columnNames</code>.
- * <p>
- * @param rowData the data for the new table
- * @param columnNames names of each column
- */
- public JTable(final Object[][] rowData, final Object[] columnNames) {
- this(new AbstractTableModel() {
- public String getColumnName(int column) { return columnNames[column].toString(); }
- public int getRowCount() { return rowData.length; }
- public int getColumnCount() { return columnNames.length; }
- public Object getValueAt(int row, int col) { return rowData[row][col]; }
- public boolean isCellEditable(int row, int column) { return true; }
- public void setValueAt(Object value, int row, int col) {
- rowData[row][col] = value;
- fireTableCellUpdated(row, col);
- }
- });
- }
- /**
- * Calls the <code>configureEnclosingScrollPane</code> method.
- *
- * @see #configureEnclosingScrollPane
- */
- public void addNotify() {
- super.addNotify();
- configureEnclosingScrollPane();
- }
- /**
- * If this <code>JTable</code> is the <code>viewportView</code> of an enclosing <code>JScrollPane</code>
- * (the usual situation), configure this <code>ScrollPane</code> by, amongst other things,
- * installing the table's <code>tableHeader</code> as the <code>columnHeaderView</code> of the scroll pane.
- * When a <code>JTable</code> is added to a <code>JScrollPane</code> in the usual way,
- * using <code>new JScrollPane(myTable)</code>, <code>addNotify</code> is
- * called in the <code>JTable</code> (when the table is added to the viewport).
- * <code>JTable</code>'s <code>addNotify</code> method in turn calls this method,
- * which is protected so that this default installation procedure can
- * be overridden by a subclass.
- *
- * @see #addNotify
- */
- protected void configureEnclosingScrollPane() {
- Container p = getParent();
- if (p instanceof JViewport) {
- Container gp = p.getParent();
- if (gp instanceof JScrollPane) {
- JScrollPane scrollPane = (JScrollPane)gp;
- // Make certain we are the viewPort's view and not, for
- // example, the rowHeaderView of the scrollPane -
- // an implementor of fixed columns might do this.
- JViewport viewport = scrollPane.getViewport();
- if (viewport == null || viewport.getView() != this) {
- return;
- }
- scrollPane.setColumnHeaderView(getTableHeader());
- // scrollPane.getViewport().setBackingStoreEnabled(true);
- Border border = scrollPane.getBorder();
- if (border == null || border instanceof UIResource) {
- scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
- }
- }
- }
- }
- /**
- * Calls the <code>unconfigureEnclosingScrollPane</code> method.
- *
- * @see #unconfigureEnclosingScrollPane
- */
- public void removeNotify() {
- unconfigureEnclosingScrollPane();
- super.removeNotify();
- }
- /**
- * Reverses the effect of <code>configureEnclosingScrollPane</code>
- * by replacing the <code>columnHeaderView</code> of the enclosing scroll pane with
- * <code>null</code>. <code>JTable</code>'s <code>removeNotify</code> method calls
- * this method, which is protected so that this default uninstallation
- * procedure can be overridden by a subclass.
- *
- * @see #removeNotify
- * @see #configureEnclosingScrollPane
- */
- protected void unconfigureEnclosingScrollPane() {
- Container p = getParent();
- if (p instanceof JViewport) {
- Container gp = p.getParent();
- if (gp instanceof JScrollPane) {
- JScrollPane scrollPane = (JScrollPane)gp;
- // Make certain we are the viewPort's view and not, for
- // example, the rowHeaderView of the scrollPane -
- // an implementor of fixed columns might do this.
- JViewport viewport = scrollPane.getViewport();
- if (viewport == null || viewport.getView() != this) {
- return;
- }
- scrollPane.setColumnHeaderView(null);
- }
- }
- }
- //
- // Static Methods
- //
- /**
- * Equivalent to <code>new JScrollPane(aTable)</code>.
- *
- * @deprecated As of Swing version 1.0.2,
- * replaced by <code>new JScrollPane(aTable)</code>.
- */
- static public JScrollPane createScrollPaneForTable(JTable aTable) {
- return new JScrollPane(aTable);
- }
- //
- // Table Attributes
- //
- /**
- * 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 newHeader new tableHeader
- * @see #getTableHeader
- * @beaninfo
- * bound: true
- * 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) {
- old.setTable(null);
- }
- this.tableHeader = tableHeader;
- if (tableHeader != null) {
- tableHeader.setTable(this);
- }
- firePropertyChange("tableHeader", old, tableHeader);
- }
- }
- /**
- * Returns the <code>tableHeader</code> used by this <code>JTable</code>.
- *
- * @return the <code>tableHeader</code> used by this table
- * @see #setTableHeader
- */
- public JTableHeader getTableHeader() {
- return tableHeader;
- }
- /**
- * Sets the height, in pixels, of all cells to <code>rowHeight</code>,
- * revalidates, and repaints.
- * The height of the cells in this row will be equal to the row height minus
- * the row margin.
- *
- * @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.
- */
- public void setRowHeight(int rowHeight) {
- if (rowHeight <= 0) {
- throw new IllegalArgumentException("New row height less than 1");
- }
- int old = this.rowHeight;
- this.rowHeight = rowHeight;
- rowModel = null;
- resizeAndRepaint();
- firePropertyChange("rowHeight", old, rowHeight);
- }
- /**
- * Returns the height of a table row, in pixels.
- * The default row height is 16.0.
- *
- * @return the height in pixels of a table row
- * @see #setRowHeight
- */
- public int getRowHeight() {
- return rowHeight;
- }
- private SizeSequence getRowModel() {
- if (rowModel == null) {
- rowModel = new SizeSequence(getRowCount(), getRowHeight());
- }
- return rowModel;
- }
- /**
- * Sets the height for <code>row</code> to <code>rowHeight</code>,
- * revalidates, and repaints. The height of the cells in this row
- * will be equal to the row height minus the row margin.
- *
- * @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>
- */
- public void setRowHeight(int row, int rowHeight) {
- if (rowHeight <= 0) {
- throw new IllegalArgumentException("New row height less than 1");
- }
- getRowModel().setSize(row, rowHeight);
- resizeAndRepaint();
- }
- /**
- * Returns the height, in pixels, of the cells in <code>row</code>.
- * @param row the row whose height is to be returned
- * @return the height, in pixels, of the cells in the row
- */
- public int getRowHeight(int row) {
- return (rowModel == null) ? getRowHeight() : rowModel.getSize(row);
- }
- /**
- * 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.
- */
- public void setRowMargin(int rowMargin) {
- int old = this.rowMargin;
- this.rowMargin = rowMargin;
- resizeAndRepaint();
- firePropertyChange("rowMargin", old, rowMargin);
- }
- /**
- * Gets the amount of empty space, in pixels, between cells. Equivalent to:
- * <code>getIntercellSpacing().height</code>.
- * @return the number of pixels between cells in a row
- *
- * @see #setRowMargin
- */
- public int getRowMargin() {
- return rowMargin;
- }
- /**
- * Sets the <code>rowMargin</code> and the <code>columnMargin</code> --
- * the height and width of the space between cells -- to
- * <code>intercellSpacing</code>.
- *
- * @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.
- */
- public void setIntercellSpacing(Dimension intercellSpacing) {
- // Set the rowMargin here and columnMargin in the TableColumnModel
- setRowMargin(intercellSpacing.height);
- getColumnModel().setColumnMargin(intercellSpacing.width);
- resizeAndRepaint();
- }
- /**
- * Returns the horizontal and vertical space between cells.
- * The default spacing is (1, 1), which provides room to draw the grid.
- *
- * @return the horizontal and vertical spacing between cells
- * @see #setIntercellSpacing
- */
- public Dimension getIntercellSpacing() {
- return new Dimension(getColumnModel().getColumnMargin(), rowMargin);
- }
- /**
- * Sets the color used to draw grid lines to <code>gridColor</code> and redisplays.
- * The default color is <code>Color.gray</code>.
- *
- * @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.
- */
- public void setGridColor(Color gridColor) {
- if (gridColor == null) {
- throw new IllegalArgumentException("New color is null");
- }
- Color old = this.gridColor;
- this.gridColor = gridColor;
- firePropertyChange("gridColor", old, gridColor);
- // Redraw
- repaint();
- }
- /**
- * Returns the color used to draw grid lines. The default color is <code>Color.gray</code>.
- *
- * @return the color used to draw grid lines
- * @see #setGridColor
- */
- public Color getGridColor() {
- return gridColor;
- }
- /**
- * Sets whether the table draws grid lines around cells.
- * If <code>showGrid</code> is true it does; if it is false it doesn't.
- * There is no <code>getShowGrid</code> method as this state is held
- * in two variables -- <code>showHorizontalLines</code> and <code>showVerticalLines</code> --
- * each of which can be queried independently.
- *
- * @param showGrid true if table view should draw grid lines
- *
- * @see #setShowVerticalLines
- * @see #setShowHorizontalLines
- * @beaninfo
- * description: The color used to draw the grid lines.
- */
- public void setShowGrid(boolean showGrid) {
- setShowHorizontalLines(showGrid);
- setShowVerticalLines(showGrid);
- // Redraw
- repaint();
- }
- /**
- * Sets whether the table draws horizontal lines between cells.
- * If <code>showHorizontalLines</code> is true it does; if it is false it doesn't.
- *
- * @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.
- */
- public void setShowHorizontalLines(boolean showHorizontalLines) {
- boolean old = showHorizontalLines;
- this.showHorizontalLines = showHorizontalLines;
- firePropertyChange("showHorizontalLines", old, showHorizontalLines);
- // Redraw
- repaint();
- }
- /**
- * Sets whether the table draws vertical lines between cells.
- * If <code>showVerticalLines</code> is true it does; if it is false it doesn't.
- *
- * @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.
- */
- public void setShowVerticalLines(boolean showVerticalLines) {
- boolean old = showVerticalLines;
- this.showVerticalLines = showVerticalLines;
- firePropertyChange("showVerticalLines", old, showVerticalLines);
- // Redraw
- repaint();
- }
- /**
- * Returns true if the table draws horizontal lines between cells, false if it
- * doesn't. The default is true.
- *
- * @return true if the table draws horizontal lines between cells, false if it
- * doesn't
- * @see #setShowHorizontalLines
- */
- public boolean getShowHorizontalLines() {
- return showHorizontalLines;
- }
- /**
- * Returns true if the table draws vertical lines between cells, false if it
- * doesn't. The default is true.
- *
- * @return true if the table draws vertical lines between cells, false if it
- * doesn't
- * @see #setShowVerticalLines
- */
- public boolean getShowVerticalLines() {
- return showVerticalLines;
- }
- /**
- * Sets the table's auto resize mode when the table is resized.
- *
- * @param 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 #getAutoResizeMode
- * @see #sizeColumnsToFit(int)
- * @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
- */
- public void setAutoResizeMode(int mode) {
- if ((mode == AUTO_RESIZE_OFF) ||
- (mode == AUTO_RESIZE_NEXT_COLUMN) ||
- (mode == AUTO_RESIZE_SUBSEQUENT_COLUMNS) ||
- (mode == AUTO_RESIZE_LAST_COLUMN) ||
- (mode == AUTO_RESIZE_ALL_COLUMNS)) {
- int old = autoResizeMode;
- autoResizeMode = mode;
- resizeAndRepaint();
- if (tableHeader != null) {
- tableHeader.resizeAndRepaint();
- }
- firePropertyChange("autoResizeMode", old, autoResizeMode);
- }
- }
- /**
- * Returns the auto resize mode of the table. The default mode
- * is AUTO_RESIZE_SUBSEQUENT_COLUMNS.
- *
- * @return the autoResizeMode of the table
- *
- * @see #setAutoResizeMode
- * @see #sizeColumnsToFit(int)
- */
- public int getAutoResizeMode() {
- return autoResizeMode;
- }
- /**
- * Sets this table's <code>autoCreateColumnsFromModel</code> flag.
- * This method calls <code>createDefaultColumnsFromModel</code> if
- * <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.
- */
- public void setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel) {
- if (this.autoCreateColumnsFromModel != autoCreateColumnsFromModel) {
- boolean old = this.autoCreateColumnsFromModel;
- this.autoCreateColumnsFromModel = autoCreateColumnsFromModel;
- if (autoCreateColumnsFromModel) {
- createDefaultColumnsFromModel();
- }
- firePropertyChange("autoCreateColumnsFromModel", old, autoCreateColumnsFromModel);
- }
- }
- /**
- * Determines whether the table will create default columns from the model.
- * If true, <code>setModel</code> will clear any existing columns and
- * create new columns from the new model. Also, if the event in
- * the <code>tableChanged</code> notification specifies that the
- * entire table changed, then the columns will be rebuilt.
- * The default is true.
- *
- * @return the autoCreateColumnsFromModel of the table
- * @see #setAutoCreateColumnsFromModel
- * @see #createDefaultColumnsFromModel
- */
- public boolean getAutoCreateColumnsFromModel() {
- return autoCreateColumnsFromModel;
- }
- /**
- * Creates default columns for the table from
- * the data model using the <code>getColumnCount</code> method
- * defined in the <code>TableModel</code> interface.
- * <p>
- * Clears any existing columns before creating the
- * new columns based on information from the model.
- *
- * @see #getAutoCreateColumnsFromModel
- */
- public void createDefaultColumnsFromModel() {
- TableModel m = getModel();
- if (m != null) {
- // Remove any current columns
- TableColumnModel cm = getColumnModel();
- while (cm.getColumnCount() > 0) {
- cm.removeColumn(cm.getColumn(0));
- }
- // Create new columns from the data model info
- for (int i = 0; i < m.getColumnCount(); i++) {
- TableColumn newColumn = new TableColumn(i);
- addColumn(newColumn);
- }
- }
- }
- /**
- * Sets a default cell renderer to be used if no renderer has been set in
- * a <code>TableColumn</code>. If renderer is <code>null</code>,
- * removes the default renderer for this column class.
- *
- * @param columnClass set the default cell renderer for this columnClass
- * @param renderer default cell renderer to be used for this
- * columnClass
- * @see #getDefaultRenderer
- * @see #setDefaultEditor
- */
- public void setDefaultRenderer(Class columnClass, TableCellRenderer renderer) {
- if (renderer != null) {
- defaultRenderersByColumnClass.put(columnClass, renderer);
- }
- else {
- defaultRenderersByColumnClass.remove(columnClass);
- }
- }
- /**
- * Returns the cell renderer to be used when no renderer has been set in
- * a <code>TableColumn</code>. During the rendering of cells the renderer is fetched from
- * a <code>Hashtable</code> of entries according to the class of the cells in the column. If
- * there is no entry for this <code>columnClass</code> the method returns
- * the entry for the most specific superclass. The <code>JTable</code> installs entries
- * for <code>Object</code>, <code>Number</code>, and <code>Boolean</code>, all of which can be modified
- * or replaced.
- *
- * @param columnClass return the default cell renderer
- * for this columnClass
- * @return the renderer for this columnClass
- * @see #setDefaultRenderer
- * @see #getColumnClass
- */
- public TableCellRenderer getDefaultRenderer(Class columnClass) {
- if (columnClass == null) {
- return null;
- }
- else {
- Object renderer = defaultRenderersByColumnClass.get(columnClass);
- if (renderer != null) {
- return (TableCellRenderer)renderer;
- }
- else {
- return getDefaultRenderer(columnClass.getSuperclass());
- }
- }
- }
- /**
- * Sets a default cell editor to be used if no editor has been set in
- * a <code>TableColumn</code>. If no editing is required in a table, or a
- * particular column in a table, uses the <code>isCellEditable</code>
- * method in the <code>TableModel</code> interface to ensure that this
- * <code>JTable</code> will not start an editor in these columns.
- * If editor is <code>null</code>, removes the default editor for this
- * column class.
- *
- * @param columnClass set the default cell editor for this columnClass
- * @param editor default cell editor to be used for this columnClass
- * @see TableModel#isCellEditable
- * @see #getDefaultEditor
- * @see #setDefaultRenderer
- */
- public void setDefaultEditor(Class columnClass, TableCellEditor editor) {
- if (editor != null) {
- defaultEditorsByColumnClass.put(columnClass, editor);
- }
- else {
- defaultEditorsByColumnClass.remove(columnClass);
- }
- }
- /**
- * Returns the editor to be used when no editor has been set in
- * a <code>TableColumn</code>. During the editing of cells the editor is fetched from
- * a <code>Hashtable</code> of entries according to the class of the cells in the column. If
- * there is no entry for this <code>columnClass</code> the method returns
- * the entry for the most specific superclass. The <code>JTable</code> installs entries
- * for <code>Object</code>, <code>Number</code>, and <code>Boolean</code>, all of which can be modified
- * or replaced.
- *
- * @param columnClass return the default cell editor for this columnClass
- * @return the default cell editor to be used for this columnClass
- * @see #setDefaultEditor
- * @see #getColumnClass
- */
- public TableCellEditor getDefaultEditor(Class columnClass) {
- if (columnClass == null) {
- return null;
- }
- else {
- Object editor = defaultEditorsByColumnClass.get(columnClass);
- if (editor != null) {
- return (TableCellEditor)editor;
- }
- else {
- return getDefaultEditor(columnClass.getSuperclass());
- }
- }
- }
- //
- // Selection methods
- //
- /**
- * Sets the table's selection mode to allow only single selections, a single
- * contiguous interval, or multiple intervals.
- * <P>
- * <bold>Note:</bold>
- * <code>JTable</code> provides all the methods for handling
- * column and row selection. When setting states,
- * such as <code>setSelectionMode</code>, it not only
- * updates the mode for the row selection model but also sets similar
- * values in the selection model of the <code>columnModel</code>.
- * If you want to have the row and column selection models operating
- * in different modes, set them both directly.
- * <p>
- * Both the row and column selection models for <code>JTable</code>
- * default to using a <code>DefaultListSelectionModel</code>
- * so that <code>JTable</code> works the same way as the
- * <code>JList</code>. See the <code>setSelectionMode</code> method
- * in <code>JList</code> for details about the modes.
- *
- * @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
- */
- public void setSelectionMode(int selectionMode) {
- clearSelection();
- getSelectionModel().setSelectionMode(selectionMode);
- getColumnModel().getSelectionModel().setSelectionMode(selectionMode);
- }
- /**
- * 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
- * description: If true, an entire row is selected for each selected cell.
- */
- public void setRowSelectionAllowed(boolean rowSelectionAllowed) {
- boolean old = this.rowSelectionAllowed;
- this.rowSelectionAllowed = rowSelectionAllowed;
- firePropertyChange("rowSelectionAllowed", old, rowSelectionAllowed);
- }
- /**
- * Returns true if rows can be selected.
- *
- * @return true if rows can be selected, otherwise false
- * @see #setRowSelectionAllowed
- */
- public boolean getRowSelectionAllowed() {
- return rowSelectionAllowed;
- }
- /**
- * 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
- * description: If true, an entire column is selected for each selected cell.
- */
- public void setColumnSelectionAllowed(boolean columnSelectionAllowed) {
- boolean old = columnModel.getColumnSelectionAllowed();
- columnModel.setColumnSelectionAllowed(columnSelectionAllowed);
- firePropertyChange("columnSelectionAllowed", old, columnSelectionAllowed);
- }
- /**
- * Returns true if columns can be selected.
- *
- * @return true if columns can be selected, otherwise false
- * @see #setColumnSelectionAllowed
- */
- public boolean getColumnSelectionAllowed() {
- return columnModel.getColumnSelectionAllowed();
- }
- /**
- * 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. Override <code>isCellSelected</code> to
- * change this default behavior. This method is equivalent to setting
- * both the <code>rowSelectionAllowed</code> property and
- * <code>columnSelectionAllowed</code> property of the
- * <code>columnModel</code> to the supplied value.
- *
- * @param cellSelectionEnabled true if simultaneous row and column
- * selection is allowed
- * @see #getCellSelectionEnabled
- * @see #isCellSelected
- * @beaninfo
- * bound: 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;
- firePropertyChange("cellSelectionEnabled", old, cellSelectionEnabled);
- }
- /**
- * Returns true if both row and column selection models are enabled.
- * Equivalent to <code>getRowSelectionAllowed() &&
- * getColumnSelectionAllowed()</code>.
- *
- * @return true if both row and column selection models are enabled
- *
- * @see #setCellSelectionEnabled
- */
- public boolean getCellSelectionEnabled() {
- return getRowSelectionAllowed() && getColumnSelectionAllowed();
- }
- /**
- * Selects all rows, columns, and cells in the table.
- */
- public void selectAll() {
- // If I'm currently editing, then I should stop editing
- if (isEditing()) {
- removeEditor();
- }
- setRowSelectionInterval(0, getRowCount()-1);
- setColumnSelectionInterval(0, getColumnCount()-1);
- }
- /**
- * Deselects all selected columns and rows.
- */
- public void clearSelection() {
- columnModel.getSelectionModel().clearSelection();
- selectionModel.clearSelection();
- }
- private int boundRow(int row) throws IllegalArgumentException {
- if (row < 0 || row >= getRowCount()) {
- throw new IllegalArgumentException("Row index out of range");
- }
- return row;
- }
- private int boundColumn(int col) {
- if (col< 0 || col >= getColumnCount()) {
- throw new IllegalArgumentException("Column index out of range");
- }
- return col;
- }
- /**
- * Selects the rows from <code>index0</code> to <code>index1</code>,
- * inclusive.
- *
- * @exception IllegalArgumentException if <code>index0</code> or
- * <code>index1</code> lie outside
- * [0, <code>getRowCount()</code>-1]
- * @param index0 one end of the interval
- * @param index1 the other end of the interval
- */
- public void setRowSelectionInterval(int index0, int index1) {
- selectionModel.setSelectionInterval(boundRow(index0), boundRow(index1));
- }
- /**
- * Selects the columns from <code>index0</code> to <code>index1</code>,
- * inclusive.
- *
- * @exception IllegalArgumentException if <code>index0</code> or
- * <code>index1</code> lie outside
- * [0, <code>getColumnCount()</code>-1]
- * @param index0 one end of the interval
- * @param index1 the other end of the interval
- */
- public void setColumnSelectionInterval(int index0, int index1) {
- columnModel.getSelectionModel().setSelectionInterval(boundColumn(index0), boundColumn(index1));
- }
- /**
- * Adds the rows from <code>index0</code> to <code>index1</code>, inclusive, to
- * the current selection.
- *
- * @exception IllegalArgumentException if <code>index0</code> or <code>index1</code>
- * lie outside [0, <code>getRowCount()</code>-1]
- * @param index0 one end of the interval
- * @param index1 the other end of the interval
- */
- public void addRowSelectionInterval(int index0, int index1) {
- selectionModel.addSelectionInterval(boundRow(index0), boundRow(index1));
- }
- /**
- * Adds the columns from <code>index0</code> to <code>index1</code>,
- * inclusive, to the current selection.
- *
- * @exception IllegalArgumentException if <code>index0</code> or
- * <code>index1</code> lie outside
- * [0, <code>getColumnCount()</code>-1]
- * @param index0 one end of the interval
- * @param index1 the other end of the interval
- */
- public void addColumnSelectionInterval(int index0, int index1) {
- columnModel.getSelectionModel().addSelectionInterval(boundColumn(index0), boundColumn(index1));
- }
- /**
- * Deselects the rows from <code>index0</code> to <code>index1</code>, inclusive.
- *
- * @exception IllegalArgumentException if <code>index0</code> or
- * <code>index1</code> lie outside
- * [0, <code>getRowCount()</code>-1]
- * @param index0 one end of the interval
- * @param index1 the other end of the interval
- */
- public void removeRowSelectionInterval(int index0, int index1) {
- selectionModel.removeSelectionInterval(boundRow(index0), boundRow(index1));
- }
- /**
- * Deselects the columns from <code>index0</code> to <code>index1</code>, inclusive.
- *
- * @exception IllegalArgumentException if <code>index0</code> or
- * <code>index1</code> lie outside
- * [0, <code>getColumnCount()</code>-1]
- * @param index0 one end of the interval
- * @param index1 the other end of the interval
- */
- public void removeColumnSelectionInterval(int index0, int index1) {
- columnModel.getSelectionModel().removeSelectionInterval(boundColumn(index0), boundColumn(index1));
- }
- /**
- * Returns the index of the first selected row, -1 if no row is selected.
- * @return the index of the first selected row
- */
- 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
- */
- public int getSelectedColumn() {
- return columnModel.getSelectionModel().getMinSelectionIndex();
- }
- /**
- * Returns the indices of all selected rows.
- *
- * @return an array of integers containing the indices of all selected rows,
- * or an empty array if no row is selected
- * @see #getSelectedRow
- */
- public int[] getSelectedRows() {
- if (selectionModel != null) {
- int iMin = selectionModel.getMinSelectionIndex();
- int iMax = selectionModel.getMaxSelectionIndex();
- if ((iMin == -1) || (iMax == -1)) {
- return new int[0];
- }
- int[] rvTmp = new int[1+ (iMax - iMin)];
- int n = 0;
- for(int i = iMin; i <= iMax; i++) {
- if (selectionModel.isSelectedIndex(i)) {
- rvTmp[n++] = i;
- }
- }
- int[] rv = new int[n];
- System.arraycopy(rvTmp, 0, rv, 0, n);
- return rv;
- }
- return new int[0];
- }
- /**
- * Returns the indices of all selected columns.
- *
- * @return an array of integers containing the indices of all selected columns,
- * or an empty array if no column is selected
- * @see #getSelectedColumn
- */
- public int[] getSelectedColumns() {
- return columnModel.getSelectedColumns();
- }
- /**
- * Returns the number of selected rows.
- *
- * @return the number of selected rows, 0 if no rows are selected
- */
- public int getSelectedRowCount() {
- if (selectionModel != null) {
- int iMin = selectionModel.getMinSelectionIndex();
- int iMax = selectionModel.getMaxSelectionIndex();
- int count = 0;
- for(int i = iMin; i <= iMax; i++) {
- if (selectionModel.isSelectedIndex(i)) {
- count++;
- }
- }
- return count;
- }
- return 0;
- }
- /**
- * Returns the number of selected columns.
- *
- * @return the number of selected columns, 0 if no columns are selected
- */
- public int getSelectedColumnCount() {
- return columnModel.getSelectedColumnCount();
- }
- /**
- * Returns true if the row at the specified index is selected.
- *
- * @return true if the row at index <code>row</code> is selected, where 0 is the
- * first row
- * @exception IllegalArgumentException if <code>row</code> is not in the
- * valid range
- */
- public boolean isRowSelected(int row) {
- if (selectionModel != null)
- return selectionModel.isSelectedIndex(row);
- return false;
- }
- /**
- * Returns true if the column at the specified index is selected.
- *
- * @param column the column in the column model
- * @return true if the column at index <code>column</code> is selected, where
- * 0 is the first column
- * @exception IllegalArgumentException if <code>column</code> is not in the
- * valid range
- */
- public boolean isColumnSelected(int column) {
- return columnModel.getSelectionModel().isSelectedIndex(column);
- }
- /**
- * Returns true if the cell at the specified position is selected.
- * @param row the row being queried
- * @param column the column being queried
- *
- * @return true if the cell at index <code>(row, column)</code> is selected,
- * where the first row and first column are at index 0
- * @exception IllegalArgumentException if <code>row</code> or <code>column</code>
- * are not in the valid range
- */
- public boolean isCellSelected(int row, int column) {
- if (!getRowSelectionAllowed() && !getColumnSelectionAllowed()) {
- return false;
- }
- return (!getRowSelectionAllowed() || isRowSelected(row)) &&
- (!getColumnSelectionAllowed() || isColumnSelected(column));
- }
- private void changeSelectionModel(ListSelectionModel sm, int index,
- boolean toggle, boolean extend) {
- if (extend) {
- if (toggle) {
- sm.setAnchorSelectionIndex(index);
- }
- else {
- sm.setLeadSelectionIndex(index);
- }
- }
- else {
- if (toggle) {
- if (sm.isSelectedIndex(index)) {
- sm.removeSelectionInterval(index, index);
- }
- else {
- sm.addSelectionInterval(index, index);
- }
- }
- else {
- sm.setSelectionInterval(index, index);
- }
- }
- }
- /**
- * Updates the selection models of the table, depending on the state of the
- * two flags: <code>toggle</code> and <code>extend</code>. All 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.
- * <p>
- * This implementation uses the following conventions:
- * <ul>
- * <li> <code>toggle</code>: <em>false</em>, <code>extend</code>: <em>false</em>.
- * Clear the previous selection and ensure the new cell is selected.
- * <li> <code>toggle</code>: <em>false</em>, <code>extend</code>: <em>true</em>.
- * Extend the previous selection to include the specified cell.
- * <li> <code>toggle</code>: <em>true</em>, <code>extend</code>: <em>false</em>.
- * If the specified cell is selected, deselect it. If it is not selected, select it.
- * <li> <code>toggle</code>: <em>true</em>, <code>extend</code>: <em>true</em>.
- * Leave the selection state as it is, but move the anchor index to the specified location.
- * </ul>
- * @param rowIndex affects the selection at <code>row</code>
- * @param columnIndex affects the selection at <code>column</code>
- * @param toggle see description above
- * @param extend if true, extend the current selection
- *
- */
- public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
- ListSelectionModel rsm = getSelectionModel();
- ListSelectionModel csm = getColumnModel().getSelectionModel();
- // Update column selection model
- changeSelectionModel(csm, columnIndex, toggle, extend);
- // Update row selection model
- changeSelectionModel(rsm, rowIndex, toggle, extend);
- // Scroll after changing the selection as blit scrolling is immediate,
- // so that if we cause the repaint after the scroll we end up painting
- // everything!
- // Autoscrolling support.
- if (getAutoscrolls()) {
- Rectangle cellRect = getCellRect(rowIndex, columnIndex, false);
- if (cellRect != null) {
- scrollRectToVisible(cellRect);
- }
- }
- }
- /**
- * Returns the foreground color for selected cells.
- *
- * @return the <code>Color</code> object for the foreground property
- * @see #setSelectionForeground
- * @see #setSelectionBackground
- */
- public Color getSelectionForeground() {
- return selectionForeground;
- }
- /**
- * Sets the foreground color for selected cells. Cell renderers
- * can use this color to render text and graphics for selected
- * cells.
- * <p>
- * The default value of this property is defined by the look
- * and feel implementation.
- * <p>
- * This is a <a href="http://java.sun.com/docs/books/tutorial/javabeans/whatis/beanDefinition.html">JavaBeans</a> bound property.