Chris Rathman / ChrisRath@aol.com

/************************************************************************
 *                                                                      *
 * javax.swing_table                                                    *
 *                                                                      *
 *    Interfaces:                                                       *
 *       TableCellEditor                 TableColumnModel               *
 *       TableCellRenderer               TableModel                     *
 *                                                                      *
 *    Classes:                                                          *
 *       AbstractTableModel              DefaultTableColumnModel        *
 *       DefaultTableCellRenderer        DefaultTableModel              *
 *       DefaultTableCellRenderer.       JTableHeader                   *
 *          UIResource                   TableColumn                    *
 *                                                                      *
 ************************************************************************/
package Test.Chris;
import javax.swing.table.*;

public class Javax_swing_table {

   public static void main(String[] args) {
      Javax_swing_table obj = new Javax_swing_table();
      obj.jframe();
      System.exit(0);
   }

   private javax.swing.JFrame myFrame = new javax.swing.JFrame("Test Frame");
   private boolean myFrameActive = true;

 //private javax.swing.JTable myTable = new javax.swing.JTable(
 //   new String[][] {{"This", "is"}, {"a", "Test"}}, new String[] {"ColumnA", "ColumnB"});

   private CMRTableModel myTableModel = new CMRTableModel();
   private javax.swing.JTable myTable = new javax.swing.JTable(myTableModel);
   private javax.swing.JScrollPane myTablePane = new javax.swing.JScrollPane(myTable);

   void jframe() {
      myTablePane.setColumnHeaderView(myTable.getTableHeader());
      tablecolumn();
      tablecolumnmodel();
      defaulttablecolumnmodel();
      tablemodel();

      defaulttablemodel();
      defaulttablecellrenderer();
      jtableheader();

      myFrame.getContentPane().setLayout(new java.awt.FlowLayout());
      myFrame.getContentPane().add(myTablePane);
      myFrame.pack();
      myFrame.setSize(400, 400);
      myFrame.setLocation(200, 200);
      myFrame.show();
      myFrame.toFront();
      myFrame.addWindowListener(
         new java.awt.event.WindowListener() {
            public void windowActivated(java.awt.event.WindowEvent e) { }
            public void windowClosed(java.awt.event.WindowEvent e) { }
            public void windowClosing(java.awt.event.WindowEvent e) { myFrameActive = false; }
            public void windowDeactivated(java.awt.event.WindowEvent e) { }
            public void windowDeiconified(java.awt.event.WindowEvent e) { }
            public void windowIconified(java.awt.event.WindowEvent e) { }
            public void windowOpened(java.awt.event.WindowEvent e) { }
         });
      while (myFrameActive) {
         try { Thread.sleep(250); } catch(InterruptedException e) { }
      }
      myFrame.dispose();                           // disposes of the frame
   }

   /*********************************************************************
    *                                                                   *
    * TableColumn:                                                      *
    *                                                                   *
    *    Fields:                                                        *
    *       CELL_RENDERER_PROPERTY        $identifier                   *
    *      $cellEditor                    $isResizable                  *
    *      $cellRenderer                  $maxWidth                     *
    *       COLUMN_WIDTH_PROPERTY         $minWidth                     *
    *       HEADER_RENDERER_PROPERTY      $modelIndex                   *
    *       HEADER_VALUE_PROPERTY         $resizedPostingDisableCount   *
    *      $headerRenderer                $width                        *
    *      $headerValue                                                 *
    *                                                                   *
    *    Methods:                                                       *
    *       addPropertyChangeListener      getWidth                     *
    *      $createDefaultHeaderRenderer    removePropertyChangeListener *
    *       disableResizedPosting          setCellEditor                *
    *       enableResizedPosting           setCellRenderer              *
    *       getCellEditor                  setHeaderRenderer            *
    *       getCellRenderer                setHeaderValue               *
    *       getHeaderRenderer              setIdentifier                *
    *       getHeaderValue                 setMaxWidth                  *
    *       getIdentifier                  setMinWidth                  *
    *       getMaxWidth                    setModelIndex                *
    *       getMinWidth                    setPreferredWidth            *
    *       getModelIndex                  setResizable                 *
    *       getPreferredWidth              setWidth                     *
    *       getResizable                   sizeWidthToFit               *
    *                                                                   *
    *********************************************************************/
   void tablecolumn() {
      int i;
      boolean f;
      String s;
      TableColumnModel tcm = myTable.getColumnModel();
      TableColumn tc = tcm.getColumn(0);
      TableCellEditor tce;
      TableCellRenderer tcr;
      TableCellRenderer tch;

      tc.sizeWidthToFit();                   // Resizes the TableColumn to fit the width of its header cell
      tc.disableResizedPosting();            // Turns off listener-notifications would otherwise occur when a column is resized
      tc.enableResizedPosting();             // Turns on listener-notifications so that listeners are once again informed when a column is resized
      tc.setResizable(true);                 // Sets whether the user can resize the receiver in its JTableView
      tc.setMaxWidth(Integer.MAX_VALUE);     // Sets the TableColumn's maximum width to newMaxWidth, also adjusting the current width if it's greater than this value
      tc.setMinWidth(15);                    // Sets the TableColumn's minimum width to newMinWidth, also adjusting the current width if it's less than this value
      tc.setModelIndex(0);                   // Sets the model index for this column
      tc.setPreferredWidth(150);             // Sets this column's preferred width to preferredWidth
      tc.setWidth(101);                      // This method should not be used to set the widths of columns in the JTable - use, setPreferredWidth() instead
    //tc.setHeaderValue("ColumnA");          // Sets the Object used as the value for the headerRenderer Posts a bound property change notification with the name HEADER_VALUE_PROPERTY
    //tc.setIdentifier("ColumnA");           // Sets the TableColumn's identifier to anIdentifier

      f = tc.getResizable();                 // Returns true if the user is allowed to resize the TableColumn width, false otherwise
      i = tc.getMaxWidth();                  // Returns the maximum width for the TableColumn
      i = tc.getMinWidth();                  // Returns the minimum width for the TableColumn
      i = tc.getModelIndex();                // Gets the model index for this column
      i = tc.getPreferredWidth();            // Returns the preferred width of the TableColumn
      i = tc.getWidth();                     // Returns the width of the TableColumn
      tce = tc.getCellEditor();              // Returns the TableCellEditor used by the JTable to draw values for this column
      tcr = tc.getCellRenderer();            // Returns the TableCellRenderer used by the JTable to draw values for this column
      tch = tc.getHeaderRenderer();          // Returns the TableCellRenderer used to draw the header of the TableColumn
      s = (String)tc.getHeaderValue();       // Returns the Object used as the value for the header renderer
      s = (String)tc.getIdentifier();        // Returns the identifier object for this column

      tce = new CMRTableCellEditor();
      tc.setCellEditor(tce);                    // Sets the TableCellEditor used by JTable to draw individual values for this column to anEditor
      tc.setCellRenderer(myTableCellRenderer);  // Sets the TableCellRenderer used by JTable to draw individual values for this column to aRenderer
      tc.setHeaderRenderer(tch);                // Sets the TableCellRenderer used to draw the TableColumn's header to aRenderer

      TableColumnAdapter adapt = new TableColumnAdapter();
      tc.addPropertyChangeListener(adapt);   // Add a PropertyChangeListener to the listener list
      tc.removePropertyChangeListener(adapt);// Remove a PropertyChangeListener from the listener list
   /*
      protected  TableCellEditor cellEditor     // The editor used to edit the data cells of the column
      protected  TableCellRenderer cellRenderer    // The renderer used to draw the data cells of the column
      protected  TableCellRenderer headerRenderer     // The renderer used to draw the header of the column
      protected  Object headerValue    // The header value of the column
      protected  Object identifier     // This object is not used internally by the drawing machinery of the JTable
      protected  boolean isResizable      // Resizable flag
      protected  int maxWidth    // The maximum width of the column
      protected  int minWidth    // The minimum width of the column
      protected  int modelIndex     // The index of the column in the model which is to be displayed by this TableColumn
      protected  int resizedPostingDisableCount    // Counter used to disable posting of resizing notifications until the end of the resize
      protected  int width    // The width of the column
      protected  TableCellRenderer tc.createDefaultHeaderRenderer();
   */
   }

   class TableColumnAdapter implements java.beans.PropertyChangeListener {
      public void propertyChange(java.beans.PropertyChangeEvent e) {
         if (e.getPropertyName().equals(TableColumn.CELL_RENDERER_PROPERTY)) { }
         if (e.getPropertyName().equals(TableColumn.COLUMN_WIDTH_PROPERTY)) { }
         if (e.getPropertyName().equals(TableColumn.HEADER_RENDERER_PROPERTY)) { }
         if (e.getPropertyName().equals(TableColumn.HEADER_VALUE_PROPERTY)) { }
      }
   }

   /*********************************************************************
    *                                                                   *
    * TableColumnModel:                                                 *
    *                                                                   *
    *    Methods:                                                       *
    *       addColumn                        getSelectedColumns         *
    *       addColumnModelListener           getSelectionModel          *
    *       getColumn                        getTotalColumnWidth        *
    *       getColumnCount                   moveColumn                 *
    *       getColumnIndex                   removeColumn               *
    *       getColumnIndexAtX                removeColumnModelListener  *
    *       getColumnMargin                  setColumnMargin            *
    *       getColumns                       setColumnSelectionAllowed  *
    *       getColumnSelectionAllowed        setSelectionModel          *
    *       getSelectedColumnCount                                      *
    *                                                                   *
    *********************************************************************/
   void tablecolumnmodel() {
      int i;
      int[] ix;
      boolean f;
      java.util.Enumeration cx;
      TableColumnModel tcm = myTable.getColumnModel();
      TableColumn tc;
      javax.swing.ListSelectionModel lsm = tcm.getSelectionModel();

      tcm.setColumnSelectionAllowed(true);         // Sets whether the columns in this model can be selected
      tcm.setColumnMargin(1);                      // Sets the TableColumn's column margin to newMargin
      tcm.moveColumn(0, 1);                        // Moves the column and heading at columnIndex to newIndex
      tcm.setSelectionModel(lsm);                  // Sets the selection model, which handles selections

      f = tcm.getColumnSelectionAllowed();         // Returns true if columns can be selected
      i = tcm.getColumnCount();                    // Returns the number of columns in the model
      i = tcm.getSelectedColumnCount();            // Returns the number of selected columns
      i = tcm.getTotalColumnWidth();               // Returns the total width of all the columns
      i = tcm.getColumnMargin();                   // Returns the width margin between each column
    //i = tcm.getColumnIndex("ColumnB");           // Returns the index of the first column in the receiver's columns array whose identifier is equal to identifier, when compared using equals()
      i = tcm.getColumnIndexAtX(20);               // Returns the index of the column that lies on the xPosition, or -1 if it lies outside the any of the column's bounds
      ix = tcm.getSelectedColumns();               // Returns an array of indexes for selected columns
      tc = tcm.getColumn(0);                       // Returns the TableColumn object for the column at columnIndex
      cx = tcm.getColumns();                       // Returns an Enumeration of all the columns in the model
      lsm = tcm.getSelectionModel();               // Returns the current selection model

      JTableColumnModelAdapter adapt = new JTableColumnModelAdapter();
      tcm.addColumnModelListener(adapt);           // Add a listener for table column model events
      tcm.removeColumnModelListener(adapt);        // Remove a listener for table column model events
   /*
      tcm.addColumn(TableColumn aColumn);      // Appends aColumn to the end of the receiver's tableColumns array
      tcm.removeColumn(TableColumn column);    // Deletes the TableColumn column from the receiver's table columns array
   */
   }

   class JTableColumnModelAdapter implements javax.swing.event.TableColumnModelListener {
      public void columnSelectionChanged(javax.swing.event.ListSelectionEvent e) { }
      public void columnMarginChanged(javax.swing.event.ChangeEvent e) { }
      public void columnAdded(javax.swing.event.TableColumnModelEvent e) { }
      public void columnRemoved(javax.swing.event.TableColumnModelEvent e) { }
      public void columnMoved(javax.swing.event.TableColumnModelEvent e) { }
   }

   /*********************************************************************
    *                                                                   *
    * DefaultTableColumnModel:                                          *
    *                                                                   *
    *    Fields:                                                        *
    *      $changeEvent                     $selectionModel             *
    *      $columnMargin                    $tableColumns               *
    *      $columnSelectionAllowed          $totalColumnWidth           *
    *      $listenerList                                                *
    *                                                                   *
    *    Methods:                                                       *
    *       addColumn                        getColumnSelectionAllowed  *
    *       addColumnModelListener           getSelectedColumnCount     *
    *      $createSelectionModel             getSelectedColumns         *
    *      $fireColumnAdded                  getSelectionModel          *
    *      $fireColumnMarginChanged          getTotalColumnWidth        *
    *      $fireColumnMoved                  moveColumn                 *
    *      $fireColumnRemoved                propertyChange             *
    *      $fireColumnSelectionChanged      $recalcWidthCache           *
    *       getColumn                        removeColumn               *
    *       getColumnCount                   removeColumnModelListener  *
    *       getColumnIndex                   setColumnMargin            *
    *       getColumnIndexAtX                setColumnSelectionAllowed  *
    *       getColumnMargin                  setSelectionModel          *
    *       getColumns                       valueChanged               *
    *                                                                   *
    *********************************************************************/
   void defaulttablecolumnmodel() {
      int i;
      int[] ix;
      boolean f;
      java.util.Enumeration cx;
      DefaultTableColumnModel tcm = (DefaultTableColumnModel)myTable.getColumnModel();
      TableColumn tc;
      javax.swing.ListSelectionModel lsm = tcm.getSelectionModel();

      tcm.setColumnSelectionAllowed(true);
      tcm.setColumnMargin(1);                      // Sets the column margin to newMargin
      tcm.moveColumn(0, 1);                        // Moves the column and heading at columnIndex to newIndex
      tcm.setSelectionModel(lsm);                  // Sets the selection model for this TableColumnModel to newModel and registers with for listner notifications from the new selection model

      f = tcm.getColumnSelectionAllowed();
      i = tcm.getColumnCount();                    // Returns the number of columns in the receiver's table columns array
      i = tcm.getSelectedColumnCount();
      i = tcm.getTotalColumnWidth();
      i = tcm.getColumnMargin();                   // Returns the width margin for TableColumn
    //i = tcm.getColumnIndex("ColumnB");           // Returns the index of the first column in the receiver's columns array whose identifier is equal to identifier, when compared using equals()
      i = tcm.getColumnIndexAtX(20);               // Returns the index of the column that lies on the xPosition, or -1 if it lies outside the any of the column's bounds
      ix = tcm.getSelectedColumns();
      tc = tcm.getColumn(0);                       // Returns the TableColumn object for the column at columnIndex
      cx = tcm.getColumns();                       // Returns an Enumeration of all the columns in the model
      lsm = tcm.getSelectionModel();               // Returns the ListSelectionModel that is used to maintain column selection state

      JTableColumnModelAdapter adapt = new JTableColumnModelAdapter();
      tcm.addColumnModelListener(adapt);           // Add a listener for table column model events
      tcm.removeColumnModelListener(adapt);        // Remove a listener for table column model events
   /*
      void addColumn(TableColumn aColumn);      // Appends aColumn to the end of the receiver's tableColumns array
      void removeColumn(TableColumn column);    // Deletes the TableColumn column from the receiver's table columns array
      void propertyChange(PropertyChangeEvent evt);
      void valueChanged(ListSelectionEvent e);

      protected  ChangeEvent changeEvent     // Change event (only one needed)
      protected  int columnMargin      // Width margin between each column
      protected  boolean columnSelectionAllowed    // Column selection allowed in this column model
      protected  EventListenerList listenerList    // List of TableColumnModelListener
      protected  ListSelectionModel selectionModel    // Model for keeping track of column selections
      protected  Vector tableColumns      // Array of TableColumn objects in this model
      protected  int totalColumnWidth     // A local cache of the combined width of all columns

      protected  void recalcWidthCache();
      protected  ListSelectionModel createSelectionModel();
      protected  void fireColumnAdded(TableColumnModelEvent e);
      protected  void fireColumnMarginChanged();
      protected  void fireColumnMoved(TableColumnModelEvent e);
      protected  void fireColumnRemoved(TableColumnModelEvent e);
      protected  void fireColumnSelectionChanged(ListSelectionEvent e);
   */
   }

   class CMRColumnModel extends DefaultTableColumnModel {
      public void addColumn(TableColumn tc) {
         super.addColumn(tc);
         moveColumn(tc.getModelIndex(), 0);
      }
   }

   /*********************************************************************
    *                                                                   *
    * TableModel:                                                       *
    *                                                                   *
    *    Methods:                                                       *
    *       addTableModelListener         getValueAt                    *
    *       getColumnClass                isCellEditable                *
    *       getColumnCount                removeTableModelListener      *
    *       getColumnName                 setValueAt                    *
    *       getRowCount                                                 *
    *                                                                   *
    *********************************************************************/
   void tablemodel() {
      int i;
      boolean f;
      String s;
      Class c;
      TableModel tm = myTableModel;

      tm.setValueAt("aha", 0, 0);            // Sets an attribute value for the record in the cell at columnIndex and rowIndex

      i = tm.getColumnCount();               // Returns the number of columns managed by the data source object
      i = tm.getRowCount();                  // Returns the number of records managed by the data source object
      f = tm.isCellEditable(0, 0);           // Returns true if the cell at rowIndex and columnIndex is editable
      s = tm.getColumnName(0);               // Returns the name of the column at columnIndex
      s = (String)tm.getValueAt(0, 0);       // Returns an attribute value for the cell at columnIndex and rowIndex
      c = tm.getColumnClass(0);              // Returns the lowest common denominator Class in the column

      TableModelAdapter adapt = new TableModelAdapter();
      tm.addTableModelListener(adapt);       // Add a listener to the list that's notified each time a change to the data model occurs
      tm.removeTableModelListener(adapt);    // Remove a listener from the list that's notified each time a change to the data model occurs
   }

   class TableModelAdapter implements javax.swing.event.TableModelListener {
      public void tableChanged(javax.swing.event.TableModelEvent e) { }
   }

   /*********************************************************************
    *                                                                   *
    * AbstractTableModel:                                               *
    *                                                                   *
    *    Fields:                                                        *
    *      $listenerList                                                *
    *                                                                   *
    *    Methods:                                                       *
    *       addTableModelListener            fireTableRowsUpdated       *
    *       findColumn                       fireTableStructureChanged  *
    *       fireTableCellUpdated             getColumnClass             *
    *       fireTableChanged                 getColumnName              *
    *       fireTableDataChanged             isCellEditable             *
    *       fireTableRowsDeleted             removeTableModelListener   *
    *       fireTableRowsInserted            setValueAt                 *
    *                                                                   *
    *********************************************************************/
   class CMRTableModel extends AbstractTableModel implements javax.swing.event.TableModelListener {
      java.util.Vector cache = new java.util.Vector();
      String[] headers;
      int colCount;

      public CMRTableModel() {
         this.addTableModelListener(this);        // Add a listener to the list that's notified each time a change to the data model occurs
         this.removeTableModelListener(this);     // Remove a listener from the list that's notified each time a change to the data model occurs

         try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");     // load JDBC:ODBC bridge
         } catch(ClassNotFoundException e) {
            System.out.println(e);
         }
         try {
            java.sql.Connection Db = java.sql.DriverManager.getConnection("jdbc:odbc:Regenit", "", "");
            java.sql.Statement Ds = Db.createStatement();
            java.sql.ResultSet Rs = Ds.executeQuery("SELECT * FROM options");
            java.sql.ResultSetMetaData Rm = Rs.getMetaData();
            colCount = Rm.getColumnCount();
            headers = new String[colCount];
            for (int i = 0; i < colCount; i++) {
               headers[i] = Rm.getColumnName(i+1);
            }
            while (Rs.next()) {
               Object[] record = new Object[colCount];
               for (int i = 0; i < colCount; i++) {
                  record[i] = Rs.getObject(i + 1);
               }
               cache.addElement(record);
            }
            Rs.close();
            Ds.close();
            Db.close();
         } catch(java.sql.SQLException e) {
            System.out.println(e);
         }
         this.fireTableChanged(null);        // Forward the given notification event to all TableModelListeners that registered themselves as listeners for this table model
      }

      public int getRowCount() { return cache.size(); }
      public int getColumnCount() { return colCount; }
      public Object getValueAt(int r, int c) { return ((Object[])cache.elementAt(r))[c]; }
      public String getColumnName(int c) { return headers[c]; }
      public void tableChanged(javax.swing.event.TableModelEvent e) { }
      public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
         Object[] record = (Object[])cache.elementAt(rowIndex);
         record[columnIndex] = aValue;
         cache.setElementAt(record, rowIndex);
         fireTableCellUpdated(rowIndex, columnIndex);    // Notify all listeners that the value of the cell at (row, column) has been updated
      }
      public boolean isCellEditable(int rowIndex, int columnIndex) { return true; }
      public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); }
   /*
      protected  EventListenerList listenerList                // List of listeners
      int findColumn(String columnName);                       // Convenience method for locating columns by name
      void fireTableDataChanged();                             // Notify all listeners that all cell values in the table's rows may have changed
      void fireTableRowsDeleted(int firstRow, int lastRow);    // Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been deleted
      void fireTableRowsInserted(int firstRow, int lastRow);   // Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been inserted
      void fireTableRowsUpdated(int firstRow, int lastRow);    // Notify all listeners that rows in the (inclusive) range [firstRow, lastRow] have been updated
      void fireTableStructureChanged();                        // Notify all listeners that the table's structure has changed
      Class getColumnClass(int columnIndex);                   // Returns Object.class by default
   */
   }

   /*********************************************************************
    *                                                                   *
    * DefaultTableModel:                                                *
    *                                                                   *
    *    Fields:                                                        *
    *      $columnIdentifiers  $dataVector                              *
    *                                                                   *
    *    Methods:                                                       *
    *       addColumn           getValueAt         rowsRemoved          *
    *       addRow              insertRow          setColumnIdentifiers *
    *      $convertToVector     isCellEditable     setDataVector        *
    *       getColumnCount      moveRow            setNumRows           *
    *       getColumnName       newDataAvailable   setValueAt           *
    *       getDataVector       newRowsAdded                            *
    *       getRowCount         removeRow                               *
    *                                                                   *
    *********************************************************************/
   void defaulttablemodel() {
   /*
      protected  Vector columnIdentifiers    // The Vector of column identifiers
      protected  Vector dataVector     // The Vector of Vector of Object values

      void addColumn(Object columnName);     // Add a column to the model
      void addColumn(Object columnName, Object[] columnData);     // Adds a column to the model with name columnName
      void addColumn(Object columnName, Vector columnData);    // Add a column to the model
      void addRow(Object[] rowData);      // Add a row to the end of the model
      void addRow(Vector rowData);     // Add a row to the end of the model
      protected static Vector convertToVector(Object[] anArray);     // Returns a Vector that contains the same objects as the array
      protected static Vector convertToVector(Object[][] anArray);      // Returns a Vector of Vectors that contains the same objects as the array
      int getColumnCount();      // Returns the number of columns in this data table
      String getColumnName(int column);      // Returns the column name
      Vector getDataVector();    // This returns the Vector of Vectors that contains the table's data values
      int getRowCount();      // Returns the number of rows in this data table
      Object getValueAt(int row, int column);      // Returns an attribute value for the cell at row and column
      void insertRow(int row, Object[] rowData);      // Insert a row at row in the model
      void insertRow(int row, Vector rowData);     // Insert a row at row in the model
      boolean isCellEditable(int row, int column);    // Returns true if the cell at row and column is editable
      void moveRow(int startIndex, int endIndex, int toIndex);    // Moves one or more rows starting at startIndex to endIndex in the model to the toIndex
      void newDataAvailable(TableModelEvent event);      // Equivalent to fireTableChanged
      void newRowsAdded(TableModelEvent event);    // This method will make sure the new rows have the correct number of columns
      void removeRow(int row);      // Remove the row at row from the model
      void rowsRemoved(TableModelEvent event);     // Equivalent to fireTableChanged()
      void setColumnIdentifiers(Object[] newIdentifiers);      // Replaces the column identifiers in the model
      void setColumnIdentifiers(Vector newIdentifiers);     // Replaces the column identifiers in the model
      void setDataVector(Object[][] newData, Object[] columnNames);     // This replaces the value in the dataVector instance variable with the values in the array newData
      void setDataVector(Vector newData, Vector columnNames);     // This replaces the current dataVector instance variable with the new Vector of rows, newData
      void setNumRows(int newSize);    // Sets the number of rows in the model
      void setValueAt(Object aValue, int row, int column);     // Sets the object value for the cell at column and row
   */
   }

   /*********************************************************************
    *                                                                   *
    * JTableHeader:                                                     *
    *                                                                   *
    *    Fields:                                                        *
    *      $columnModel                     $resizingAllowed            *
    *      $draggedColumn                   $resizingColumn             *
    *      $draggedDistance                 $table                      *
    *      $reorderingAllowed               $updateTableInRealTime      *
    *                                                                   *
    *    Methods:                                                       *
    *       columnAdded                      getUI                      *
    *       columnAtPoint                    getUIClassID               *
    *       columnMarginChanged              getUpdateTableInRealTime   *
    *       columnMoved                     $initializeLocalVars        *
    *       columnRemoved                   $paramString                *
    *       columnSelectionChanged           resizeAndRepaint           *
    *      $createDefaultColumnModel         setColumnModel             *
    *       getAccessibleContext             setDraggedColumn           *
    *       getColumnModel                   setDraggedDistance         *
    *       getDraggedColumn                 setReorderingAllowed       *
    *       getDraggedDistance               setResizingAllowed         *
    *       getHeaderRect                    setResizingColumn          *
    *       getReorderingAllowed             setTable                   *
    *       getResizingAllowed               setUI                      *
    *       getResizingColumn                setUpdateTableInRealTime   *
    *       getTable                         updateUI                   *
    *       getToolTipText                                              *
    *                                                                   *
    *********************************************************************/
   void jtableheader() {
      int i;
      boolean f;
      String s;
      javax.swing.JTable jt;
      TableColumn tc;
      JTableHeader jth = myTable.getTableHeader();

      jth.resizeAndRepaint();                         // Properly sizes the receiver and its header view, and marks it as needing display
      jth.setReorderingAllowed(true);            // Sets whether the user can drag column headers to reorder columns
      jth.setResizingAllowed(true);              // Sets whether the user can resize columns by dragging between headers
      jth.updateUI();                                 // Notification from the UIManager that the L&F has changed

      f = jth.getReorderingAllowed();     // Returns true if the receiver allows the user to rearrange columns by dragging their headers, false otherwise
      f = jth.getResizingAllowed();    // Returns true if the receiver allows the user to resize columns by dragging between their headers, false otherwise
      f = jth.getUpdateTableInRealTime();    // Returns true if the receiver updates the body of the table view in real time when a column is resized or dragged
      i = jth.columnAtPoint(new java.awt.Point(10,10));     // Returns the index of the column that point lies in, or -1 if it lies outside the receiver's bounds
      jt = jth.getTable();      // Returns the header's partner table
      tc = jth.getResizingColumn();    // Returns the resizing column
      tc = jth.getDraggedColumn();     // Returns the the dragged column, if and only if a drag is in process
      s = jth.getUIClassID();     // Returns the name of the L&F class that renders this component


   /*
      AccessibleContext getAccessibleContext();    // Get the AccessibleContext associated with this JComponent
      TableColumnModel getColumnModel();     // Returns the TableColumnModel that contains all column inforamtion of this table header
      int getDraggedDistance();     // Returns the column's horizontal distance from its original position, if and only if a drag is in process
      Rectangle getHeaderRect(int columnIndex);    // Returns the rectangle containing the header tile at columnIndex
      TableHeaderUI getUI();     // Returns the L&F object that renders this component

      String getToolTipText(MouseEvent event);     // Overriding to allow renderer's tips to be used if it has text set
      void columnAdded(TableColumnModelEvent e);
      void columnMarginChanged(ChangeEvent e);
      void columnMoved(TableColumnModelEvent e);
      void columnRemoved(TableColumnModelEvent e);
      void columnSelectionChanged(ListSelectionEvent e);

      jth.setColumnModel(TableColumnModel newModel);  // Sets the column model for this table to newModel and registers with for listner notifications from the new column model
      jth.setDraggedColumn(TableColumn aColumn);      // Sets the header's draggedColumn to aColumn
      jth.setDraggedDistance(int distance);           // Sets the header's draggedDistance to distance
      jth.setResizingColumn(TableColumn aColumn);     // Sets the header's resizingColumn to aColumn
      jth.setTable(JTable aTable);                    // Sets the header's partner table to aTable
      jth.setUI(TableHeaderUI ui);                    // Sets the L&F object that renders this component
      jth.setUpdateTableInRealTime(boolean flag);     // Sets whether the body of the table updates in real time when a column is resized or dragged
   */
   }

   /*********************************************************************
    *                                                                   *
    * TableCellRenderer:                                                *
    *                                                                   *
    *    Methods:                                                       *
    *       getTableCellRendererComponent                               *
    *                                                                   *
    *********************************************************************/
   TableCellRenderer myTableCellRenderer = new CMRTableCellRenderer();
   class CMRTableCellRenderer extends javax.swing.JButton implements TableCellRenderer {
      public CMRTableCellRenderer() {
         super();
      }

      // This method is sent to the renderer by the drawing table to configure the renderer appropriately before drawing
      public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value,
         boolean isSelected, boolean hasFocus, int row, int column) {
         this.setText((String)value);
         return this;
      }
   }
   /*********************************************************************
    *                                                                   *
    * DefaultTableCellRenderer:                                         *
    *                                                                   *
    *    Fields:                                                        *
    *       $noFocusBorder                                              *
    *                                                                   *
    *    Methods:                                                       *
    *       getTableCellRendererComponent   $setValue                   *
    *       setBackground                    updateUI                   *
    *       setForeground                                               *
    *                                                                   *
    *********************************************************************/
   void defaulttablecellrenderer() {
   /*
      protected static Border noFocusBorder

      Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column);
      void setBackground(Color c);     // Overrides JComponent.setForeground to specify the unselected-background color using the specified color
      void setForeground(Color c);     // Overrides JComponent.setForeground to specify the unselected-foreground color using the specified color
      protected  void setValue(Object value);
      void updateUI();     // Notification from the UIManager that the L&F has changed
   */
   }

   /*********************************************************************
    *                                                                   *
    * TableCellEditor:                                                  *
    *                                                                   *
    *    Methods:                                                       *
    *       getTableCellEditorComponent                                 *
    *                                                                   *
    *********************************************************************/
   class CMRTableCellEditor extends javax.swing.DefaultCellEditor implements TableCellEditor {
      public CMRTableCellEditor() {
         super(new javax.swing.JTextField(20));
      }

      // Sets an initial value for the editor
      public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table,
         Object value, boolean isSelected, int row, int column) {
         return this.getComponent();
      }
   }
}

Chris Rathman / ChrisRath@aol.com