Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.table
Class AdvancedJTable

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
                  extended by com.sciapp.table.AdvancedJTable
All Implemented Interfaces:
VetoableTableColumnModelListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, TableColumnModelListener, TableModelListener, Scrollable
Direct Known Subclasses:
TreeTable, TreeTable

public class AdvancedJTable
extends JTable
implements VetoableTableColumnModelListener

AdvancedJTable is a sublass of JTable that makes full use of classes contained in this library, so as to add extra functionality to the JTable Swing component.

The most important features that were added are:

1) There is the option to add a dummy column to the table header with no data underneath, for decorative purposes. This option is available if the table is enclosed by an AdvancedJScrollPane, in which case, it can be controlled with setShowDummyColumn.

2) Define default editors and renderers to those in the com.sciapp.editors and com.sciapp.renderers respectively

3) Autoresize table columns upon double-clicking on a table column border. (see TableAssistant)

4) Display a popup through which the columns of the table can be dynamically added/removed. (see TableAssistant)

5) Use a table header whose columns cannot be reordered with right mouse button clicks. (see AdvancedTableHeader)

6) Correctly handle selection changes when the tabular data are restructured. (see TableReorder)

7) Programmatically alter the table columns displayed and their widths. (see setTableState(java.lang.String))

8) Ability to merge and split cells. (see SpanModel)

9) Display a row header. (see JTableRowHeader)

10) Use Styles for easy cell rendering. (see StyleModel)

11) Make the first column of the table not movable. (see setFirstColumnFixed(boolean))

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  TableCellResizer cellResizer
          object that adds cell-resizing functionality to a JTable
static int COMMIT_EDIT
          an edit mode committing edited values when the model changes
static int CONTINUE_EDIT
          an edit mode continuing editing when the model changes
static int DISCARD_EDIT
          an edit mode discarding edited values when the model changes
protected  int editMode
          the edit mode that defines the behaviour of the table when its model changes
protected  boolean isFirstColumnFixed
          boolean flag to indicate whether the first column of the table is fixed.
protected  boolean nonContiguousCellSelection
          flag indicating whether non-contiguous cell selection is enabled
protected  NonContiguousSelectionModel nonContiguousSelectionModel
          the non-contiguous selection model
protected  RowHeader rowHeader
          the table's row header
protected  AdvancedJScrollPane scroller
          the scrollpane this table is enclosed by
protected  boolean showRowHeader
          boolean flag to indicate whether the row header should be visible.
protected  SpanDrawer spanDrawer
          the span drawer.
protected  StyleModel styleModel
          the style model.
protected  TableAssistant tableAssistant
          the table assistant
protected  TableReorder tableReorder
          This is the TableReorder object.
protected  ViewableResizer viewableResizer
          the viewable resizer.
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AdvancedJTable()
          Constructs a default AdvancedJTable which is initialized with a default data model, a default column model, and a default selection model.
AdvancedJTable(int numRows, int numColumns)
          Constructs an AdvancedJTable with numRows and numColumns of empty cells using the DefaultTableModel.
AdvancedJTable(Object[][] rowData, Object[] columnNames)
          Constructs an AdvancedJTable to display the values in the two dimensional array, rowData, with column names, columnNames.
AdvancedJTable(TableModel dm)
          Constructs a JTable which is initialized with dm as the data model, a default column model, and a default selection model.
AdvancedJTable(TableModel dm, TableColumnModel cm)
          Constructs an AdvancedJTable which is initialized with dm as the data model, cm as the column model, and a default selection model.
AdvancedJTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
          Constructs an AdvancedJTable which is initialized with dm as the data model, cm as the column model, and sm as the selection model.
AdvancedJTable(Vector rowData, Vector columnNames)
          Constructs an AdvancedJTable to display the values in the Vector of Vectors, rowData, with column names, columnNames.
 
Method Summary
 void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
          Updates the selection models of the table, depending on the state of the two flags: toggle and extend.
 void columnSelectionChanged(ListSelectionEvent e)
          Invoked when the selection model of the TableColumnModel is changed.
 void columnWillBeAdded(TableColumnModelEvent e)
          Invoked whenever a table column is about to be added.
 void columnWillBeMoved(TableColumnModelEvent e)
          Invoked whenever a table column is about to be moved.
 void columnWillBeRemoved(TableColumnModelEvent e)
          Invoked whenever a table column is about to be removed.
protected  void configureEnclosingScrollPane()
          If this JTable is the viewportView of an enclosing JScrollPane (the usual situation), configure this ScrollPane by, amongst other things, installing the table's tableHeader as the columnHeaderView of the scroll pane.
 TableCellResizer createDefaultCellResizer()
          Creates and returns a cell resizer.
protected  TableColumnModel createDefaultColumnModel()
          Returns a new instance of DefaultVetoableColumnModel.
 void createDefaultColumnsFromModel()
          Creates default columns for the table from the data model using the getColumnCount method defined in the TableModel interface.
protected  void createDefaultEditors()
          Creates default cell editors for objects, numbers, and boolean values.
protected  NonContiguousSelectionModel createDefaultNonContiguousSelectionModel()
          Creates and returns a non-contiguous cell selection model
protected  void createDefaultRenderers()
          Creates default cell renderers for objects, numbers, doubles, dates, booleans, and icons.
protected  RowHeader createDefaultRowHeader()
          Returns the default row header object which is a ListRowHeader.
protected  StyleModel createDefaultStyleModel()
          Returns the default style model object which is a DefaultStyleModel.
protected  TableAssistant createDefaultTableAssistant()
          Creates and returns the table assistant.
protected  JTableHeader createDefaultTableHeader()
          Returns a new instance of FilterTableHeader.
protected  TableReorder createReorder()
          Creates and returns a TableReorder that will handle table selection changes.
protected  SpanDrawer createSpanDrawer()
          Returns a new instance of the span drawer that is used to enable cell spanning.
protected  void doEdit(TableModelEvent e, int newRow)
          Discards, commits or continues editing after a model update, according to the table's edit mode.
protected  void doEdit(TableModelEvent e, int newRow, int editMode)
          Discards, commits or continues editing after a model update, according to the edit mode, passed as parameter.
protected  void doProcessMouseEvent(MouseEvent e)
          Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.
protected  void doProcessMouseMotionEvent(MouseEvent e)
          Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.
 boolean editCellAt(int row, int column, EventObject e)
          Programmatically starts editing the cell at row and column, if the cell is editable.
 void editingStopped(ChangeEvent e)
          Invoked when editing is finished.
 TableCellResizer getCellResizer()
          Returns the cell resizer associated with this table.
 Class getColumnClass(int column)
          Returns the type of the column appearing in the view at column position column.
 String getColumnName(int column)
          Returns the name of the column appearing in the view at column position column.
 int getEditingRow()
          This method has been overriden in order to take into account the presence of the span model.
 int getEditMode()
          Determines the behaviour of the table when it is being edited and its model changes.
 boolean getNonContiguousCellSelection()
          Determines whether non-contiguous cell selection is enabled.
 NonContiguousSelectionModel getNonContiguousSelectionModel()
          Returns the non-contiguous cell selection model that is associated with this table.
 int getRealEditingRow()
          Returns the index of the editing row.
 RowHeader getRowHeader()
          Returns the RowHeader used by this JTable.
 JScrollPane getScrollPane()
          Utility method that returns the scrollpane this table is enclosed by.
 boolean getShowDummyColumn()
          Determines whether the table is set to show the dummy column.
 boolean getShowRowHeader()
          Determines whether the row header should be displayed.
 SpanDrawer getSpanDrawer()
          Returns the span drawer that is used to enable cell spanning.
 StyleModel getStyleModel()
          Returns the style model used.
 TableAssistant getTableAssistant()
          Returns the table assistant instance associated with this table.
 TableReorder getTableReorder()
          Returns the TableReorder that will handle table selection changes.
 String getTableState()
          Returns a string showing which columns are shown and their corresponding widths.
 Point getToolTipLocation(MouseEvent event)
          Returns the tooltip location in this component's coordinate system.
 String getToolTipText(MouseEvent event)
          Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set.
 Object getValueAt(int row, int column)
          Returns the cell value at row and column.
 ViewableResizer getViewableResizer()
          Retrieves the object that paints cells with their contents resized to their viewable dimensions.
protected  boolean handleEvent(MouseEvent e, Component comp)
          Handles a mouse event on the table.
protected  void initializeLocalVars()
          Initializes table properties to their default values.
 boolean isCellEditable(int row, int column)
          Returns true if the cell at row and column is editable.
 boolean isCellSelected(int row, int column)
          Returns true if the cell at the specified position is selected.
 boolean isDummyColumn(int column)
          Determines if the supplied column is the last dummy column.
 boolean isFirstColumnFixed()
          Determines whether the first column of the table can be removed or reordered.
 Component prepareEditor(TableCellEditor editor, int row, int column)
          Prepares the editor by querying the data model for the value and selection state of the cell at row, column.
 Component prepareRenderer(TableCellRenderer renderer, int row, int column)
          Prepares the renderer by querying the data model for the value and selection state of the cell at row, column.
protected  void processMouseEvent(MouseEvent e)
          This method is overriden so that the mouse event is appropriately converted due to the presence of fixed/locked columns/rows.
protected  void processMouseMotionEvent(MouseEvent e)
          This method is overriden so that the mouse event is appropriately converted due to the presence of fixed/locked columns/rows.
 void removeEditor()
          Discards the editor object and frees the real estate it used for cell rendering.
 void scrollRectToVisible(Rectangle aRect)
          Forwards the scrollRectToVisible() message to the JComponent's parent.
 void selectAll()
          Selects all rows, columns, and cells in the table.
 void setAutoResizeMode(int mode)
          Sets the table's auto resize mode when the table is resized.
 void setCellResizer(TableCellResizer cellResizer)
          Assigns a cell resizer to this table.
 void setColumnModel(TableColumnModel newModel)
          Sets the column model for this table to newModel and registers for listener notifications from the new column model.
 void setEditMode(int editMode)
          Determines the behaviour of the table when it is being edited and its model changes.
 void setEvenColor(Color evenColor)
          Utility method to set the color for painting the even rows of the table by looking for an instance of DefaultStyle in the style model's list of styles.
 void setFirstColumnFixed(boolean isFirstColumnFixed)
          Assigns a boolean flag that is true if the first column of the table can be removed or reordered.
 void setModel(TableModel newModel)
          Sets the data model for this table to newModel and registers with it for listener notifications from the new data model.
 void setNonContiguousCellSelection(boolean nonContiguousCellSelection)
          Determines whether non-contiguous cell selection is enabled.
 void setNonContiguousSelectionModel(NonContiguousSelectionModel nonContiguousSelectionModel)
          Assigns a non-contiguous cell selection model to this table.
 void setOddColor(Color oddColor)
          Utility method to set the color for painting the odd rows of the table by looking for an instance of DefaultStyle in the style model's list of styles.
 void setRowHeader(RowHeader newRowHeader)
          Sets the RowHeader working with this JTable to newRowHeader.
 void setShowDummyColumn(boolean showDummyColumn)
          Sets this table's showLastColumn flag.
 void setShowRowHeader(boolean newShowRowHeader)
          Sets whether or not the row header should be displayed.
 void setSpanDrawer(SpanDrawer newSpanDrawer)
          Sets the span drawer that is used to enable cell spanning.
 void setStyleModel(StyleModel styleModel)
          Sets a new style model to be used.
 void setTableAssistant(TableAssistant tableAssistant)
          Assigns the table assistant instance associated with this table.
 void setTableHeader(JTableHeader newHeader)
          Sets the tableHeader working with this JTable to newHeader.
 void setTableReorder(TableReorder newTableReorder)
          Assigns a table reorder that will handle table selection changes.
 void setTableState(String state)
          Set which columns will be shown and their corresponding widths.
 void sizeColumnsToFit(int resizingColumn)
          Obsolete as of Java 2 platform v1.4.
 void tableChanged(TableModelEvent e)
          Invoked when this table's TableModel generates a TableModelEvent.
 void updateUI()
          Notification from the UIManager that the L&F has changed.
 void valueChanged(ListSelectionEvent e)
          Invoked when the row selection changes -- repaints to show the new selection.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, convertColumnIndexToModel, convertColumnIndexToView, createDefaultDataModel, createDefaultSelectionModel, createScrollPaneForTable, doLayout, editCellAt, editingCanceled, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnCount, getColumnModel, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getUI, getUIClassID, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, setAutoCreateColumnsFromModel, setCellEditor, setCellSelectionEnabled, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setUI, setValueAt, sizeColumnsToFit, unconfigureEnclosingScrollPane
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DISCARD_EDIT

public static final int DISCARD_EDIT
an edit mode discarding edited values when the model changes

See Also:
Constant Field Values

COMMIT_EDIT

public static final int COMMIT_EDIT
an edit mode committing edited values when the model changes

See Also:
Constant Field Values

CONTINUE_EDIT

public static final int CONTINUE_EDIT
an edit mode continuing editing when the model changes

See Also:
Constant Field Values

editMode

protected int editMode
the edit mode that defines the behaviour of the table when its model changes


nonContiguousCellSelection

protected boolean nonContiguousCellSelection
flag indicating whether non-contiguous cell selection is enabled


nonContiguousSelectionModel

protected transient NonContiguousSelectionModel nonContiguousSelectionModel
the non-contiguous selection model


cellResizer

protected transient TableCellResizer cellResizer
object that adds cell-resizing functionality to a JTable


tableReorder

protected transient TableReorder tableReorder
This is the TableReorder object.


isFirstColumnFixed

protected boolean isFirstColumnFixed
boolean flag to indicate whether the first column of the table is fixed.


rowHeader

protected transient RowHeader rowHeader
the table's row header


showRowHeader

protected boolean showRowHeader
boolean flag to indicate whether the row header should be visible.


styleModel

protected transient StyleModel styleModel
the style model.


spanDrawer

protected transient SpanDrawer spanDrawer
the span drawer.


viewableResizer

protected transient ViewableResizer viewableResizer
the viewable resizer.


scroller

protected transient AdvancedJScrollPane scroller
the scrollpane this table is enclosed by


tableAssistant

protected transient TableAssistant tableAssistant
the table assistant

Constructor Detail

AdvancedJTable

public AdvancedJTable()
Constructs a default AdvancedJTable which is initialized with a default data model, a default column model, and a default selection model.


AdvancedJTable

public AdvancedJTable(Object[][] rowData,
                      Object[] columnNames)
Constructs an AdvancedJTable to display the values in the two dimensional array, rowData, with column names, columnNames. rowData is an Array of rows, so the value of the cell at row 1, column 5 can be obtained with the following code:

 rowData[1][5]; 

All rows must be of the same length as columnNames.


AdvancedJTable

public AdvancedJTable(int numRows,
                      int numColumns)
Constructs an AdvancedJTable with numRows and numColumns of empty cells using the DefaultTableModel. The columns will have names of the form "A", "B", "C", etc.


AdvancedJTable

public AdvancedJTable(Vector rowData,
                      Vector columnNames)
Constructs an AdvancedJTable to display the values in the Vector of Vectors, rowData, with column names, columnNames. The Vectors contained in rowData 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:

((Vector)rowData.elementAt(1)).elementAt(5);

All rows must be of the same length as columnNames.


AdvancedJTable

public AdvancedJTable(TableModel dm)
Constructs a JTable which is initialized with dm as the data model, a default column model, and a default selection model.


AdvancedJTable

public AdvancedJTable(TableModel dm,
                      TableColumnModel cm)
Constructs an AdvancedJTable which is initialized with dm as the data model, cm as the column model, and a default selection model.


AdvancedJTable

public AdvancedJTable(TableModel dm,
                      TableColumnModel cm,
                      ListSelectionModel sm)
Constructs an AdvancedJTable which is initialized with dm as the data model, cm as the column model, and sm as the selection model. If any of the parameters are null this method will initialize the table with the corresponding default model. The autoCreateColumnsFromModel flag is set to false if cm is non-null, otherwise it is set to true and the column model is populated with suitable TableColumns for the columns in dm.

Method Detail

changeSelection

public void changeSelection(int rowIndex,
                            int columnIndex,
                            boolean toggle,
                            boolean extend)
Updates the selection models of the table, depending on the state of the two flags: toggle and extend. 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.

This implementation uses the following conventions:

Overrides:
changeSelection in class JTable
Parameters:
rowIndex - affects the selection at row
columnIndex - affects the selection at column
toggle - see description above
extend - if true, extend the current selection

columnSelectionChanged

public void columnSelectionChanged(ListSelectionEvent e)
Invoked when the selection model of the TableColumnModel is changed.

Application code will not use these methods explicitly, they are used internally by JTable.

Specified by:
columnSelectionChanged in interface TableColumnModelListener
Overrides:
columnSelectionChanged in class JTable
Parameters:
e - the event received
See Also:
TableColumnModelListener

columnWillBeAdded

public void columnWillBeAdded(TableColumnModelEvent e)
                       throws ColumnModelVetoException
Invoked whenever a table column is about to be added.

Specified by:
columnWillBeAdded in interface VetoableTableColumnModelListener
Parameters:
e - the event identifying the addition.
Throws:
ColumnModelVetoException

columnWillBeMoved

public void columnWillBeMoved(TableColumnModelEvent e)
                       throws ColumnModelVetoException
Invoked whenever a table column is about to be moved.

Specified by:
columnWillBeMoved in interface VetoableTableColumnModelListener
Parameters:
e - the event identifying the move.
Throws:
ColumnModelVetoException

columnWillBeRemoved

public void columnWillBeRemoved(TableColumnModelEvent e)
                         throws ColumnModelVetoException
Invoked whenever a table column is about to be removed.

Specified by:
columnWillBeRemoved in interface VetoableTableColumnModelListener
Parameters:
e - the event identifying the removal.
Throws:
ColumnModelVetoException

configureEnclosingScrollPane

protected void configureEnclosingScrollPane()
If this JTable is the viewportView of an enclosing JScrollPane (the usual situation), configure this ScrollPane by, amongst other things, installing the table's tableHeader as the columnHeaderView of the scroll pane. When a JTable is added to a JScrollPane in the usual way, using new JScrollPane(myTable), addNotify is called in the JTable (when the table is added to the viewport). JTable's addNotify method in turn calls this method, which is protected so that this default installation procedure can be overridden by a subclass.

Overrides:
configureEnclosingScrollPane in class JTable
See Also:
JTable.addNotify()

createDefaultCellResizer

public TableCellResizer createDefaultCellResizer()
Creates and returns a cell resizer.

Returns:
a new instance of TableCellResizer

createDefaultColumnModel

protected TableColumnModel createDefaultColumnModel()
Returns a new instance of DefaultVetoableColumnModel.

Returns the default column model object, which is a DefaultTableColumnModel. A subclass can override this method to return a different column model object.

Overrides:
createDefaultColumnModel in class JTable
Returns:
the default column model object
See Also:
DefaultTableColumnModel

createDefaultColumnsFromModel

public void createDefaultColumnsFromModel()
Creates default columns for the table from the data model using the getColumnCount method defined in the TableModel interface.

Clears any existing columns before creating the new columns based on information from the model.

Overrides:
createDefaultColumnsFromModel in class JTable
See Also:
JTable.getAutoCreateColumnsFromModel()

createDefaultEditors

protected void createDefaultEditors()
Creates default cell editors for objects, numbers, and boolean values.

Overrides:
createDefaultEditors in class JTable
See Also:
DefaultCellEditor

createDefaultNonContiguousSelectionModel

protected NonContiguousSelectionModel createDefaultNonContiguousSelectionModel()
Creates and returns a non-contiguous cell selection model

Returns:
a new instance of NonContiguousSelectionModel

createDefaultRenderers

protected void createDefaultRenderers()
Creates default cell renderers for objects, numbers, doubles, dates, booleans, and icons.

Overrides:
createDefaultRenderers in class JTable
See Also:
DefaultTableCellRenderer

createDefaultRowHeader

protected RowHeader createDefaultRowHeader()
Returns the default row header object which is a ListRowHeader.

Returns:
the default row header object

createDefaultStyleModel

protected StyleModel createDefaultStyleModel()
Returns the default style model object which is a DefaultStyleModel.

Returns:
the default style model object

createDefaultTableAssistant

protected TableAssistant createDefaultTableAssistant()
Creates and returns the table assistant.

Returns:
a new instance of TableAssistant

createDefaultTableHeader

protected JTableHeader createDefaultTableHeader()
Returns a new instance of FilterTableHeader.

Returns the default table header object, which is a JTableHeader. A subclass can override this method to return a different table header object.

Overrides:
createDefaultTableHeader in class JTable
Returns:
the default table header object
See Also:
JTableHeader

createReorder

protected TableReorder createReorder()
Creates and returns a TableReorder that will handle table selection changes.

Returns:
a new instance of TableReorder

createSpanDrawer

protected SpanDrawer createSpanDrawer()
Returns a new instance of the span drawer that is used to enable cell spanning.

Returns:
a SpanDrawer instance.

doEdit

protected void doEdit(TableModelEvent e,
                      int newRow)
Discards, commits or continues editing after a model update, according to the table's edit mode. see getEditMode.

Parameters:
e - the model update event triggering the method
newRow - the new row index of the row being edited

doEdit

protected void doEdit(TableModelEvent e,
                      int newRow,
                      int editMode)
Discards, commits or continues editing after a model update, according to the edit mode, passed as parameter. see getEditMode.

Parameters:
e - the model update event triggering the method
newRow - the new row index of the row being edited
editMode - the edit mode

doProcessMouseEvent

protected void doProcessMouseEvent(MouseEvent e)
Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.

Parameters:
e - the 'converted' mouse event

doProcessMouseMotionEvent

protected void doProcessMouseMotionEvent(MouseEvent e)
Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.

Parameters:
e - the 'converted' mouse event

editCellAt

public boolean editCellAt(int row,
                          int column,
                          EventObject e)
Programmatically starts editing the cell at row and column, if the cell is editable. To prevent the JTable from editing a particular table, column or cell value, return false from the isCellEditable method in the TableModel interface.

Overrides:
editCellAt in class JTable
Parameters:
row - the row to be edited
column - the column to be edited
e - event to pass into shouldSelectCell; note that as of Java 2 platform v1.2, the call to shouldSelectCell is no longer made
Returns:
false if for any reason the cell cannot be edited

editingStopped

public void editingStopped(ChangeEvent e)
Invoked when editing is finished. The changes are saved and the editor is discarded.

Application code will not use these methods explicitly, they are used internally by JTable.

Specified by:
editingStopped in interface CellEditorListener
Overrides:
editingStopped in class JTable
Parameters:
e - the event received
See Also:
CellEditorListener

getCellResizer

public TableCellResizer getCellResizer()
Returns the cell resizer associated with this table.

Returns:
the cell resizer

getColumnClass

public Class getColumnClass(int column)
Returns the type of the column appearing in the view at column position column.

Overrides:
getColumnClass in class JTable
Parameters:
column - the column in the view being queried
Returns:
the type of the column at position column in the view where the first column is column 0

getColumnName

public String getColumnName(int column)
Returns the name of the column appearing in the view at column position column.

Overrides:
getColumnName in class JTable
Parameters:
column - the column in the view being queried
Returns:
the name of the column at position column in the view where the first column is column 0

getEditingRow

public int getEditingRow()
This method has been overriden in order to take into account the presence of the span model. Do not use this method to get the editing row, use getRealEditingRow instead.

Returns the index of the row that contains the cell currently being edited. If nothing is being edited, returns -1.

Overrides:
getEditingRow in class JTable
Returns:
the index of the row that contains the cell currently being edited; returns -1 if nothing being edited
See Also:
JTable.editingColumn

getEditMode

public int getEditMode()
Determines the behaviour of the table when it is being edited and its model changes. When the table's data model changes, rows may have been removed or reorganized. If a row being edited before a model update, dissappears from the view after the update, the table will stop editing. If, however, the row is displaced, the edit mode will define how the editing will take place.
There are three modes:
DISCARD_EDIT: editing will stop, discarding any changes. This is the default behaviour.
COMMIT_EDIT: editing will stop, committing any changes.
CONTINUE_EDIT: editing will continue, moving the editing row to the new position of the row being edited.

Returns:
the edit mode

getNonContiguousCellSelection

public boolean getNonContiguousCellSelection()
Determines whether non-contiguous cell selection is enabled.

Returns:
true if non-contiguous cell selection is enabled, false otherwise

getNonContiguousSelectionModel

public NonContiguousSelectionModel getNonContiguousSelectionModel()
Returns the non-contiguous cell selection model that is associated with this table.

Returns:
the non-contiguous cell selection model

getRealEditingRow

public int getRealEditingRow()
Returns the index of the editing row.

Returns:
the index of the row being edited
See Also:
JTable.editingColumn

getRowHeader

public RowHeader getRowHeader()
Returns the RowHeader used by this JTable.

Returns:
the RowHeader used by this table.
See Also:
setRowHeader(com.sciapp.table.RowHeader)

getScrollPane

public JScrollPane getScrollPane()
Utility method that returns the scrollpane this table is enclosed by.

Returns:
the enclosing scrollpane, or null if this table is not enclosed by a JScrollPane.

getShowDummyColumn

public boolean getShowDummyColumn()
Determines whether the table is set to show the dummy column. Note that if the value returned is true, this does not guarantee that the dummy column is shown, since the table must also be enclosed by an AdvancedJScrollPane.

Returns:
true if the table is set to show the last column, false otherwise.

getShowRowHeader

public boolean getShowRowHeader()
Determines whether the row header should be displayed.

Returns:
true if the row header should be visible, false otherwise.

getSpanDrawer

public SpanDrawer getSpanDrawer()
Returns the span drawer that is used to enable cell spanning.

Returns:
the currently associated span drawer.

getStyleModel

public StyleModel getStyleModel()
Returns the style model used.

Returns:
the currently associated style model.

getTableAssistant

public TableAssistant getTableAssistant()
Returns the table assistant instance associated with this table.

Returns:
the table assistant.

getTableReorder

public TableReorder getTableReorder()
Returns the TableReorder that will handle table selection changes.

Returns:
the TableReorder object

getTableState

public String getTableState()
Returns a string showing which columns are shown and their corresponding widths. The string is formatted as follows: i1:w1,i2:w2,... where i is the column's model index and w its width.

Returns:
a string showing which columns are shown and their corresponding widths.

getToolTipLocation

public Point getToolTipLocation(MouseEvent event)
Returns the tooltip location in this component's coordinate system. If null is returned, Swing will choose a location. The default implementation returns null.

Overrides:
getToolTipLocation in class JComponent
Parameters:
event - the MouseEvent that caused the ToolTipManager to show the tooltip
Returns:
always returns null

getToolTipText

public String getToolTipText(MouseEvent event)
Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set.

Note: For JTable to properly display tooltips of its renderers JTable must be a registered component with the ToolTipManager. This is done automatically in initializeLocalVars, but if at a later point JTable is told setToolTipText(null) it will unregister the table component, and no tips from renderers will display anymore.

Overrides:
getToolTipText in class JTable
See Also:
JComponent.getToolTipText()

getValueAt

public Object getValueAt(int row,
                         int column)
Returns the cell value at row and column.

Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering.

Overrides:
getValueAt in class JTable
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the Object at the specified cell

getViewableResizer

public ViewableResizer getViewableResizer()
Retrieves the object that paints cells with their contents resized to their viewable dimensions.

Returns:
the object that resizes cells to their viewable dimensions

handleEvent

protected boolean handleEvent(MouseEvent e,
                              Component comp)
Handles a mouse event on the table. This method is called before the event is propagated to any mouse listeners.

Parameters:
e - the mouse event that triggered the method
comp - the drawn table cell component
Returns:
true, if the event should be consumed, false otherwise

initializeLocalVars

protected void initializeLocalVars()
Initializes table properties to their default values.

Overrides:
initializeLocalVars in class JTable

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns true if the cell at row and column is editable. Otherwise, invoking setValueAt on the cell will have no effect.

Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering.

Overrides:
isCellEditable in class JTable
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
true if the cell is editable
See Also:
JTable.setValueAt(java.lang.Object, int, int)

isCellSelected

public boolean isCellSelected(int row,
                              int column)
Returns true if the cell at the specified position is selected.

Overrides:
isCellSelected in class JTable
Parameters:
row - the row being queried
column - the column being queried
Returns:
true if the cell at index (row, column) is selected, where the first row and first column are at index 0

isDummyColumn

public boolean isDummyColumn(int column)
Determines if the supplied column is the last dummy column.

Parameters:
column - the index of the table column
Returns:
true if the supplied column is the last dummy column, false otherwise.

isFirstColumnFixed

public boolean isFirstColumnFixed()
Determines whether the first column of the table can be removed or reordered.

Returns:
true if we can remove or reorder the first column, false otherwise.

prepareEditor

public Component prepareEditor(TableCellEditor editor,
                               int row,
                               int column)
Prepares the editor by querying the data model for the value and selection state of the cell at row, column.

Note: Throughout the table package, the internal implementations always use this method to prepare editors so that this default behavior can be safely overridden by a subclass.

Overrides:
prepareEditor in class JTable
Parameters:
editor - the TableCellEditor to set up
row - the row of the cell to edit, where 0 is the first row
column - the column of the cell to edit, where 0 is the first column
Returns:
the Component being edited

prepareRenderer

public Component prepareRenderer(TableCellRenderer renderer,
                                 int row,
                                 int column)
Prepares the renderer by querying the data model for the value and selection state of the cell at row, column. Returns the component (may be a Component or a JComponent) under the event location.

Note: Throughout the table package, the internal implementations always use this method to prepare renderers so that this default behavior can be safely overridden by a subclass.

Overrides:
prepareRenderer in class JTable
Parameters:
renderer - the TableCellRenderer to prepare
row - the row of the cell to render, where 0 is the first row
column - the column of the cell to render, where 0 is the first column
Returns:
the Component under the event location

processMouseEvent

protected void processMouseEvent(MouseEvent e)
This method is overriden so that the mouse event is appropriately converted due to the presence of fixed/locked columns/rows. The doProcessMouseEvent method is then called.

Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.

This method is not called unless mouse events are enabled for this component. Mouse events are enabled when one of the following occurs:

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Overrides:
processMouseEvent in class Component
Parameters:
e - the mouse event
See Also:
MouseEvent, MouseListener, Component.addMouseListener(java.awt.event.MouseListener), Component.enableEvents(long)

processMouseMotionEvent

protected void processMouseMotionEvent(MouseEvent e)
This method is overriden so that the mouse event is appropriately converted due to the presence of fixed/locked columns/rows. The doProcessMouseMotionEvent method is then called.

Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.

Overrides:
processMouseMotionEvent in class JComponent
Parameters:
e - the MouseEvent
See Also:
MouseEvent

removeEditor

public void removeEditor()
Discards the editor object and frees the real estate it used for cell rendering.

Overrides:
removeEditor in class JTable

scrollRectToVisible

public void scrollRectToVisible(Rectangle aRect)
Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as JViewport, override this method and perform the scrolling.

Overrides:
scrollRectToVisible in class JComponent
Parameters:
aRect - the visible Rectangle
See Also:
JViewport

selectAll

public void selectAll()
Selects all rows, columns, and cells in the table.

Overrides:
selectAll in class JTable

setAutoResizeMode

public void setAutoResizeMode(int mode)
Sets the table's auto resize mode when the table is resized.

Overrides:
setAutoResizeMode in class JTable
Parameters:
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 Also:
JTable.getAutoResizeMode(), JTable.doLayout()

setCellResizer

public void setCellResizer(TableCellResizer cellResizer)
Assigns a cell resizer to this table.

Parameters:
cellResizer - the cell resizer

setColumnModel

public void setColumnModel(TableColumnModel newModel)
Sets the column model for this table to newModel and registers for listener notifications from the new column model. Also sets the column model of the JTableHeader to columnModel.

Overrides:
setColumnModel in class JTable
Parameters:
newModel - the new data source for this table
See Also:
JTable.getColumnModel()

setEditMode

public void setEditMode(int editMode)
Determines the behaviour of the table when it is being edited and its model changes. see getEditMode.

Parameters:
editMode - the edit mode

setEvenColor

public void setEvenColor(Color evenColor)
Utility method to set the color for painting the even rows of the table by looking for an instance of DefaultStyle in the style model's list of styles. If the style model does not contain a DefaultStyle, this method will do nothing. AdvancedJTable installs a DefaultStyle upon initialization. The easiest way to remove it will be by calling styleModel.clearStyles();

Parameters:
evenColor - the even row color

setFirstColumnFixed

public void setFirstColumnFixed(boolean isFirstColumnFixed)
Assigns a boolean flag that is true if the first column of the table can be removed or reordered.

Parameters:
isFirstColumnFixed - a boolean which is true if we are able to remove or reorder the first column.

setModel

public void setModel(TableModel newModel)
Sets the data model for this table to newModel and registers with it for listener notifications from the new data model.

Overrides:
setModel in class JTable
Parameters:
newModel - the new data source for this table
See Also:
JTable.getModel()

setNonContiguousCellSelection

public void setNonContiguousCellSelection(boolean nonContiguousCellSelection)
Determines whether non-contiguous cell selection is enabled.

Parameters:
nonContiguousCellSelection - true if non-contiguous cell selection is enabled, false otherwise

setNonContiguousSelectionModel

public void setNonContiguousSelectionModel(NonContiguousSelectionModel nonContiguousSelectionModel)
Assigns a non-contiguous cell selection model to this table.

Parameters:
nonContiguousSelectionModel - the non-contiguous cell selection model

setOddColor

public void setOddColor(Color oddColor)
Utility method to set the color for painting the odd rows of the table by looking for an instance of DefaultStyle in the style model's list of styles. If the style model does not contain a DefaultStyle, this method will do nothing. AdvancedJTable installs a DefaultStyle upon initialization. The easiest way to remove it will be by calling styleModel.clearStyles();

Parameters:
oddColor - the odd row color

setRowHeader

public void setRowHeader(RowHeader newRowHeader)
Sets the RowHeader working with this JTable to newRowHeader.

Parameters:
newRowHeader - the new RowHeader
See Also:
getRowHeader()

setShowDummyColumn

public void setShowDummyColumn(boolean showDummyColumn)
Sets this table's showLastColumn flag. Note that even if showLastColumn is true, this does not guarantee that the last column will be actually shown.


setShowRowHeader

public void setShowRowHeader(boolean newShowRowHeader)
Sets whether or not the row header should be displayed.

Parameters:
newShowRowHeader - true if the row header should be visible, false otherwise.

setSpanDrawer

public void setSpanDrawer(SpanDrawer newSpanDrawer)
Sets the span drawer that is used to enable cell spanning.

Parameters:
newSpanDrawer - the associated span drawer

setStyleModel

public void setStyleModel(StyleModel styleModel)
Sets a new style model to be used.

Parameters:
styleModel - the new style model to assign.

setTableAssistant

public void setTableAssistant(TableAssistant tableAssistant)
Assigns the table assistant instance associated with this table.

Parameters:
tableAssistant - the table assistant to assign

setTableHeader

public void setTableHeader(JTableHeader newHeader)
Sets the tableHeader working with this JTable to newHeader. It is legal to have a null tableHeader.

Overrides:
setTableHeader in class JTable
Parameters:
newHeader - new tableHeader
See Also:
JTable.getTableHeader()

setTableReorder

public void setTableReorder(TableReorder newTableReorder)
Assigns a table reorder that will handle table selection changes.

Parameters:
newTableReorder - the TableReorder object to assign.

setTableState

public void setTableState(String state)
Set which columns will be shown and their corresponding widths. state is formatted as follows: i1:w1,i2:w2,... where i is the column's model index and w its width. A column which is removed by calling this method can always be added later if its model index is supplied. Only columns that are removed via the removeColumn method of JTable are permanently removed from the table.

Parameters:
state - a string showing which columns will be shown and their corresponding widths.

sizeColumnsToFit

public void sizeColumnsToFit(int resizingColumn)
Obsolete as of Java 2 platform v1.4. Please use the doLayout() method instead.

Overrides:
sizeColumnsToFit in class JTable
Parameters:
resizingColumn - the column whose resizing made this adjustment necessary or -1 if there is no such column
See Also:
JTable.doLayout()

tableChanged

public void tableChanged(TableModelEvent e)
Invoked when this table's TableModel generates a TableModelEvent. The TableModelEvent should be constructed in the coordinate system of the model; the appropriate mapping to the view coordinate system is performed by this JTable when it receives the event.

Application code will not use these methods explicitly, they are used internally by JTable.

Note that as of 1.3, this method clears the selection, if any.

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class JTable

updateUI

public void updateUI()
Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.

Overrides:
updateUI in class JTable
See Also:
JComponent.updateUI()

valueChanged

public void valueChanged(ListSelectionEvent e)
Invoked when the row selection changes -- repaints to show the new selection.

Application code will not use these methods explicitly, they are used internally by JTable.

Specified by:
valueChanged in interface ListSelectionListener
Overrides:
valueChanged in class JTable
Parameters:
e - the event received
See Also:
ListSelectionListener

Copyright © 2005 Scientific Applications. All Rights Reserved.