JTable is a user-interface component that displays data in a two-
dimensional table format.
The user-interface works as follows:
The user can select a column by pressing the left or right arrow keys
to move to the desired column, and then pressing ENTER.
He/she can select a row by pressing the up and down arrow keys to move to
the desired row, then pressing ENTER.
Depending on the value of the selection mode, multiple rows and/or columns
may be selected. By default the selection mode is set to SINGLE_SELECTION
so that only a single row or column can be selected at a time. Selection
of rows and/or columns can be enabled/disabled by means of the
setRowSelectionAllowed() and setColumnSelectionAllowed() methods.
addColumnSelectionInterval
public void addColumnSelectionInterval(int index0_,
int index1_)
Adds the columns from index0_
to index1_
,
inclusive, to the current selection.
addRowSelectionInterval
public void addRowSelectionInterval(int index0_,
int index1_)
Adds the rows from index0_
to index1_
,
inclusive, to the current selection.
getColumnSelectionAllowed
public boolean getColumnSelectionAllowed()
Returns true if columns can be selected; otherwise false.
getRowSelectionAllowed
public boolean getRowSelectionAllowed()
Returns true if rows can be selected; otherwise false.
getSelectedColumn
public int getSelectedColumn()
Returns the index of the first selected column, or -1 if
no column is selected.
getSelectedColumnCount
public int getSelectedColumnCount()
Returns the number of selected columns.
getSelectedColumns
public int[] getSelectedColumns()
Returns an array of the indices of all selected columns.
getSelectedRow
public int getSelectedRow()
Returns the index of the first selected row, or -1 if
no row is selected.
getSelectedRowCount
public int getSelectedRowCount()
Returns the number of selected rows.
getSelectedRows
public int[] getSelectedRows()
Returns an array of the indices of all selected rows.
getSelectionMode
public int getSelectionMode()
Returns the table's row/column selection mode.
getSelectionModel
public ListSelectionModel getSelectionModel()
Returns the table's row selection model.
getValueAt
public Object getValueAt(int row_,
int column_)
isColumnSelected
public boolean isColumnSelected(int column_)
Returns true if the column with the specified index is selected.
isRowSelected
public boolean isRowSelected(int row_)
Returns true if the row with the specified index is selected.
setColumnSelectionAllowed
public void setColumnSelectionAllowed(boolean allowed_)
Set whether selection of columns is allowed.
setColumnSelectionInterval
public void setColumnSelectionInterval(int index0_,
int index1_)
Selects the columns from index0_
to index1_
,
inclusive.
setModel
public void setModel(TableModel model_)
Sets the data model to the specified TableModel and registers with it
as a listener for events from the model.
setPreferredScrollableViewportSize
public void setPreferredScrollableViewportSize(Dimension size_)
setRowSelectionAllowed
public void setRowSelectionAllowed(boolean allowed_)
Set whether selection of rows is allowed.
setRowSelectionInterval
public void setRowSelectionInterval(int index0_,
int index1_)
Selects the rows from index0_
to index1_
,
inclusive.
setSelectionMode
public void setSelectionMode(int mode_)
Sets the table's selection mode to allow selection of either single
rows and/or columns, or multiple rows and/or columns.
mode_
- the selection mode. Allowable values are
ListSelectionModel.SINGLE_SELECTION and
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION.
setSelectionModel
public void setSelectionModel(ListSelectionModel model_)
Sets the table's row selection model and registers for notifications
from the new selection model.
setValueAt
public void setValueAt(Object object_,
int row_,
int column_)
tableChanged
public void tableChanged(TableModelEvent evt_)
This method implements the TableModelListener interface;
it is invoked when this table's TableModel generates a
TableModelEvent.
- tableChanged in interface TableModelListener