charvax.swing
Class JTable

java.lang.Object
  extended bycharva.awt.Component
      extended bycharvax.swing.JComponent
          extended bycharvax.swing.JTable
All 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
_alignmentX, _alignmentY, _background, _cursesColor, _enabled, _focusListeners, _foreground, _keyListeners, _origin, _parent, _visible, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
JTable()
          Default constructor
JTable(int numRows_, int numColumns_)
          Constructs a table of numRows_ and numColumns_ of empty cells using a DefaultTableModel.
JTable(java.lang.Object[][] data_, java.lang.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.
 
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()
           
 java.lang.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()
          This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.
 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(java.lang.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
getBorder, getInsets, setBorder
 
Methods inherited from class charva.awt.Component
addFocusListener, addKeyListener, contains, contains, getAlignmentX, getAlignmentY, getAncestorWindow, getBackground, getBounds, getCursesColor, getForeground, getLocation, getLocationOnScreen, getName, getParent, hasFocus, hide, invalidate, isDisplayed, isEnabled, isFocusTraversable, isTotallyObscured, isValid, isVisible, processEvent, processFocusEvent, processMouseEvent, repaint, requestSync, setBackground, setBounds, setBounds, setBounds, setEnabled, setForeground, setLocation, setLocation, setName, setParent, setVisible, show, validate, validateCursesColor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface charva.awt.Scrollable
getLocation
 

Field Detail

_rowSelectionModel

protected ListSelectionModel _rowSelectionModel

_columnSelectionModel

protected ListSelectionModel _columnSelectionModel
Constructor Detail

JTable

public JTable()
Default constructor


JTable

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


JTable

public JTable(java.lang.Object[][] data_,
              java.lang.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.

Method Detail

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.


getModel

public TableModel getModel()

setValueAt

public void setValueAt(java.lang.Object object_,
                       int row_,
                       int column_)

getValueAt

public java.lang.Object getValueAt(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

requestFocus

public void requestFocus()
Description copied from class: Component
This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.

Overrides:
requestFocus in class Component

draw

public void draw()
Description copied from class: JComponent
Draws the border of the component (if there is one).

Overrides:
draw in class JComponent

processKeyEvent

public void processKeyEvent(KeyEvent ke_)
Processes key events occurring on this object

Overrides:
processKeyEvent in class Component

addScrollListener

public void addScrollListener(ScrollListener sl_)
Register a ScrollListener object for this table.

Specified by:
addScrollListener 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

processScrollEvent

public void processScrollEvent(ScrollEvent e_)
Process scroll events generated by this JTable.

Specified by:
processScrollEvent in interface Scrollable

getSize

public Dimension getSize()
Specified by:
getSize in class Component

minimumSize

public Dimension minimumSize()
Specified by:
minimumSize in class Component

getWidth

public int getWidth()
Specified by:
getWidth in class Component

getHeight

public int getHeight()
Specified by:
getHeight in class Component

setPreferredScrollableViewportSize

public void setPreferredScrollableViewportSize(Dimension size_)

getPreferredScrollableViewportSize

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

setSelectionModel

public void setSelectionModel(ListSelectionModel model_)
Sets the table's row selection model and registers for notifications from the new selection model.


getSelectionModel

public ListSelectionModel getSelectionModel()
Returns the table's row selection model.


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.

getSelectionMode

public int getSelectionMode()
Returns the table's row/column selection mode.


setColumnSelectionAllowed

public void setColumnSelectionAllowed(boolean allowed_)
Set whether selection of columns is allowed.


getColumnSelectionAllowed

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


setRowSelectionAllowed

public void setRowSelectionAllowed(boolean allowed_)
Set whether selection of rows is allowed.


getRowSelectionAllowed

public boolean getRowSelectionAllowed()
Returns true if rows can be selected; otherwise false.


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.


setColumnSelectionInterval

public void setColumnSelectionInterval(int index0_,
                                       int index1_)
Selects the columns from index0_ to index1_, inclusive.


setRowSelectionInterval

public void setRowSelectionInterval(int index0_,
                                    int index1_)
Selects the rows from index0_ to index1_, inclusive.


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.


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.


isRowSelected

public boolean isRowSelected(int row_)
Returns true if the row with the specified index is selected.


isColumnSelected

public boolean isColumnSelected(int column_)
Returns true if the column with the specified index is selected.


valueChanged

public void valueChanged(ListSelectionEvent e_)
This method is invoked when the row selection changes.

Specified by:
valueChanged in interface ListSelectionListener

debug

public void debug(int level_)
Specified by:
debug in class Component