charvax.swing

Class JTable

Implemented Interfaces:
EventListener, ListSelectionListener, Scrollable, TableModelListener

public class JTable
extends JComponent
implements TableModelListener, Scrollable, ListSelectionListener

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.

Field Summary

protected ListSelectionModel
_columnSelectionModel
protected ListSelectionModel
_rowSelectionModel

Fields inherited from class charvax.swing.JComponent

_border

Fields inherited from class charva.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT, _alignmentX, _alignmentY, _background, _cursesColor, _enabled, _focusListeners, _foreground, _keyListeners, _origin, _parent, _visible

Constructor Summary

JTable()
Default constructor
JTable(Object[][] data_, Object[] columnNames_)
Construct a JTable from the specified data and column names, using a DefaultTableModel.
JTable(TableModel model_)
Construct a JTable with the specified data model.
JTable(int numRows_, int numColumns_)
Constructs a table of numRows_ and numColumns_ of empty cells using a DefaultTableModel.

Method Summary

void
addColumnSelectionInterval(int index0_, int index1_)
Adds the columns from index0_ to index1_, inclusive, to the current selection.
void
addRowSelectionInterval(int index0_, int index1_)
Adds the rows from index0_ to index1_, inclusive, to the current selection.
void
addScrollListener(ScrollListener sl_)
Register a ScrollListener object for this table.
void
debug(int level_)
void
draw()
Draws the border of the component (if there is one).
boolean
getColumnSelectionAllowed()
Returns true if columns can be selected; otherwise false.
int
getHeight()
TableModel
getModel()
Dimension
getPreferredScrollableViewportSize()
boolean
getRowSelectionAllowed()
Returns true if rows can be selected; otherwise false.
int
getSelectedColumn()
Returns the index of the first selected column, or -1 if no column is selected.
int
getSelectedColumnCount()
Returns the number of selected columns.
int[]
getSelectedColumns()
Returns an array of the indices of all selected columns.
int
getSelectedRow()
Returns the index of the first selected row, or -1 if no row is selected.
int
getSelectedRowCount()
Returns the number of selected rows.
int[]
getSelectedRows()
Returns an array of the indices of all selected rows.
int
getSelectionMode()
Returns the table's row/column selection mode.
ListSelectionModel
getSelectionModel()
Returns the table's row selection model.
Dimension
getSize()
Object
getValueAt(int row_, int column_)
int
getWidth()
boolean
isColumnSelected(int column_)
Returns true if the column with the specified index is selected.
boolean
isRowSelected(int row_)
Returns true if the row with the specified index is selected.
Dimension
minimumSize()
void
processKeyEvent(KeyEvent ke_)
Processes key events occurring on this object
void
processScrollEvent(ScrollEvent e_)
Process scroll events generated by this JTable.
void
removeScrollListener(ScrollListener sl_)
Remove a ScrollListener object that is registered for this table.
void
requestFocus()
void
setColumnSelectionAllowed(boolean allowed_)
Set whether selection of columns is allowed.
void
setColumnSelectionInterval(int index0_, int index1_)
Selects the columns from index0_ to index1_, inclusive.
void
setModel(TableModel model_)
Sets the data model to the specified TableModel and registers with it as a listener for events from the model.
void
setPreferredScrollableViewportSize(Dimension size_)
void
setRowSelectionAllowed(boolean allowed_)
Set whether selection of rows is allowed.
void
setRowSelectionInterval(int index0_, int index1_)
Selects the rows from index0_ to index1_, inclusive.
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.
void
setSelectionModel(ListSelectionModel model_)
Sets the table's row selection model and registers for notifications from the new selection model.
void
setValueAt(Object object_, int row_, int column_)
void
tableChanged(TableModelEvent evt_)
This method implements the TableModelListener interface; it is invoked when this table's TableModel generates a TableModelEvent.
void
valueChanged(ListSelectionEvent e_)
This method is invoked when the row selection changes.

Methods inherited from class charvax.swing.JComponent

draw, getBorder, getInsets, setBorder

Methods inherited from class charva.awt.Component

addFocusListener, addKeyListener, contains, contains, debug, draw, getAlignmentX, getAlignmentY, getAncestorWindow, getBackground, getBounds, getCursesColor, getForeground, getHeight, getLocation, getLocationOnScreen, getName, getParent, getSize, getWidth, hasFocus, hide, invalidate, isDisplayed, isEnabled, isFocusTraversable, isTotallyObscured, isValid, isVisible, minimumSize, processEvent, processFocusEvent, processKeyEvent, processMouseEvent, repaint, requestFocus, requestSync, setBackground, setEnabled, setForeground, setLocation, setLocation, setName, setParent, setVisible, show, validate, validateCursesColor

Field Details

_columnSelectionModel

protected ListSelectionModel _columnSelectionModel

_rowSelectionModel

protected ListSelectionModel _rowSelectionModel

Constructor Details

JTable

public JTable()
Default constructor

JTable

public JTable(Object[][] data_,
              Object[] columnNames_)
Construct a JTable from the specified data and column names, using a DefaultTableModel.

JTable

public JTable(TableModel model_)
Construct a JTable with the specified data model.

JTable

public JTable(int numRows_,
              int numColumns_)
Constructs a table of numRows_ and numColumns_ of empty cells using a DefaultTableModel.

Method Details

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.

addScrollListener

public void addScrollListener(ScrollListener sl_)
Register a ScrollListener object for this table.
Specified by:
addScrollListener in interface Scrollable

debug

public void debug(int level_)
Overrides:
debug in interface Component

draw

public void draw()
Draws the border of the component (if there is one).
Overrides:
draw in interface JComponent

getColumnSelectionAllowed

public boolean getColumnSelectionAllowed()
Returns true if columns can be selected; otherwise false.

getHeight

public int getHeight()
Overrides:
getHeight in interface Component

getModel

public TableModel getModel()

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface Scrollable

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.

getSize

public Dimension getSize()
Overrides:
getSize in interface Component

getValueAt

public Object getValueAt(int row_,
                         int column_)

getWidth

public int getWidth()
Overrides:
getWidth in interface Component

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.

minimumSize

public Dimension minimumSize()
Overrides:
minimumSize in interface Component

processKeyEvent

public void processKeyEvent(KeyEvent ke_)
Processes key events occurring on this object
Overrides:
processKeyEvent in interface Component

processScrollEvent

public void processScrollEvent(ScrollEvent e_)
Process scroll events generated by this JTable.
Specified by:
processScrollEvent in interface Scrollable

removeScrollListener

public void removeScrollListener(ScrollListener sl_)
Remove a ScrollListener object that is registered for this table.
Specified by:
removeScrollListener in interface Scrollable

requestFocus

public void requestFocus()
Overrides:
requestFocus in interface Component

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.
Parameters:
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.
Specified by:
tableChanged in interface TableModelListener

valueChanged

public void valueChanged(ListSelectionEvent e_)
This method is invoked when the row selection changes.
Specified by:
valueChanged in interface ListSelectionListener