< prev index next >

src/demo/share/jfc/TableExample/OldJTable.java

Print this page




  55 @SuppressWarnings("serial")
  56 public class OldJTable extends JTable
  57 {
  58    /*
  59     *  A new convenience method returning the index of the column in the
  60     *  co-ordinate space of the view.
  61     */
  62     public int getColumnIndex(Object identifier) {
  63         return getColumnModel().getColumnIndex(identifier);
  64     }
  65 
  66 //
  67 //  Methods deleted from the JTable because they only work with the
  68 //  DefaultTableModel.
  69 //
  70 
  71     public TableColumn addColumn(Object columnIdentifier, int width) {
  72         return addColumn(columnIdentifier, width, null, null, null);
  73     }
  74 
  75     public TableColumn addColumn(Object columnIdentifier, List columnData) {
  76         return addColumn(columnIdentifier, -1, null, null, columnData);
  77     }
  78 
  79     // Override the new JTable implementation - it will not add a column to the
  80     // DefaultTableModel.
  81     public TableColumn addColumn(Object columnIdentifier, int width,
  82                                  TableCellRenderer renderer,
  83                                  TableCellEditor editor) {
  84         return addColumn(columnIdentifier, width, renderer, editor, null);
  85     }
  86 
  87     public TableColumn addColumn(Object columnIdentifier, int width,
  88                                  TableCellRenderer renderer,
  89                                  TableCellEditor editor, List columnData) {
  90         checkDefaultTableModel();
  91 
  92         // Set up the model side first
  93         DefaultTableModel m = (DefaultTableModel)getModel();
  94         m.addColumn(columnIdentifier, columnData.toArray());
  95 
  96         // The column will have been added to the end, so the index of the
  97         // column in the model is the last element.
  98         TableColumn newColumn = new TableColumn(
  99                 m.getColumnCount()-1, width, renderer, editor);
 100         super.addColumn(newColumn);
 101         return newColumn;
 102     }
 103 
 104     // Not possilble to make this work the same way ... change it so that
 105     // it does not delete columns from the model.
 106     public void removeColumn(Object columnIdentifier) {
 107         super.removeColumn(getColumn(columnIdentifier));
 108     }
 109 
 110     public void addRow(Object[] rowData) {
 111         checkDefaultTableModel();
 112         ((DefaultTableModel)getModel()).addRow(rowData);
 113     }
 114 
 115     public void addRow(List rowData) {
 116         checkDefaultTableModel();
 117         ((DefaultTableModel)getModel()).addRow(rowData.toArray());
 118     }
 119 
 120     public void removeRow(int rowIndex) {
 121         checkDefaultTableModel();
 122         ((DefaultTableModel)getModel()).removeRow(rowIndex);
 123     }
 124 
 125     public void moveRow(int startIndex, int endIndex, int toIndex) {
 126         checkDefaultTableModel();
 127         ((DefaultTableModel)getModel()).moveRow(startIndex, endIndex, toIndex);
 128     }
 129 
 130     public void insertRow(int rowIndex, Object[] rowData) {
 131         checkDefaultTableModel();
 132         ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData);
 133     }
 134 
 135     public void insertRow(int rowIndex, List rowData) {
 136         checkDefaultTableModel();
 137         ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData.toArray());
 138     }
 139 
 140     public void setNumRows(int newSize) {
 141         checkDefaultTableModel();
 142         ((DefaultTableModel)getModel()).setNumRows(newSize);
 143     }
 144 
 145     public void setDataVector(Object[][] newData, List columnIds) {
 146         checkDefaultTableModel();
 147         ((DefaultTableModel)getModel()).setDataVector(
 148                 newData, columnIds.toArray());
 149     }
 150 
 151     public void setDataVector(Object[][] newData, Object[] columnIds) {
 152         checkDefaultTableModel();
 153         ((DefaultTableModel)getModel()).setDataVector(newData, columnIds);
 154     }
 155 
 156     protected void checkDefaultTableModel() {
 157         if(!(dataModel instanceof DefaultTableModel))
 158             throw new InternalError("In order to use this method, the data model must be an instance of DefaultTableModel.");
 159     }
 160 
 161 //
 162 //  Methods removed from JTable in the move from identifiers to ints.
 163 //
 164 
 165     public Object getValueAt(Object columnIdentifier, int rowIndex) {




  55 @SuppressWarnings("serial")
  56 public class OldJTable extends JTable
  57 {
  58    /*
  59     *  A new convenience method returning the index of the column in the
  60     *  co-ordinate space of the view.
  61     */
  62     public int getColumnIndex(Object identifier) {
  63         return getColumnModel().getColumnIndex(identifier);
  64     }
  65 
  66 //
  67 //  Methods deleted from the JTable because they only work with the
  68 //  DefaultTableModel.
  69 //
  70 
  71     public TableColumn addColumn(Object columnIdentifier, int width) {
  72         return addColumn(columnIdentifier, width, null, null, null);
  73     }
  74 
  75     public TableColumn addColumn(Object columnIdentifier, List<?> columnData) {
  76         return addColumn(columnIdentifier, -1, null, null, columnData);
  77     }
  78 
  79     // Override the new JTable implementation - it will not add a column to the
  80     // DefaultTableModel.
  81     public TableColumn addColumn(Object columnIdentifier, int width,
  82                                  TableCellRenderer renderer,
  83                                  TableCellEditor editor) {
  84         return addColumn(columnIdentifier, width, renderer, editor, null);
  85     }
  86 
  87     public TableColumn addColumn(Object columnIdentifier, int width,
  88                                  TableCellRenderer renderer,
  89                                  TableCellEditor editor, List<?> columnData) {
  90         checkDefaultTableModel();
  91 
  92         // Set up the model side first
  93         DefaultTableModel m = (DefaultTableModel)getModel();
  94         m.addColumn(columnIdentifier, columnData.toArray());
  95 
  96         // The column will have been added to the end, so the index of the
  97         // column in the model is the last element.
  98         TableColumn newColumn = new TableColumn(
  99                 m.getColumnCount()-1, width, renderer, editor);
 100         super.addColumn(newColumn);
 101         return newColumn;
 102     }
 103 
 104     // Not possilble to make this work the same way ... change it so that
 105     // it does not delete columns from the model.
 106     public void removeColumn(Object columnIdentifier) {
 107         super.removeColumn(getColumn(columnIdentifier));
 108     }
 109 
 110     public void addRow(Object[] rowData) {
 111         checkDefaultTableModel();
 112         ((DefaultTableModel)getModel()).addRow(rowData);
 113     }
 114 
 115     public void addRow(List<?> rowData) {
 116         checkDefaultTableModel();
 117         ((DefaultTableModel)getModel()).addRow(rowData.toArray());
 118     }
 119 
 120     public void removeRow(int rowIndex) {
 121         checkDefaultTableModel();
 122         ((DefaultTableModel)getModel()).removeRow(rowIndex);
 123     }
 124 
 125     public void moveRow(int startIndex, int endIndex, int toIndex) {
 126         checkDefaultTableModel();
 127         ((DefaultTableModel)getModel()).moveRow(startIndex, endIndex, toIndex);
 128     }
 129 
 130     public void insertRow(int rowIndex, Object[] rowData) {
 131         checkDefaultTableModel();
 132         ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData);
 133     }
 134 
 135     public void insertRow(int rowIndex, List<?> rowData) {
 136         checkDefaultTableModel();
 137         ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData.toArray());
 138     }
 139 
 140     public void setNumRows(int newSize) {
 141         checkDefaultTableModel();
 142         ((DefaultTableModel)getModel()).setNumRows(newSize);
 143     }
 144 
 145     public void setDataVector(Object[][] newData, List<?> columnIds) {
 146         checkDefaultTableModel();
 147         ((DefaultTableModel)getModel()).setDataVector(
 148                 newData, columnIds.toArray());
 149     }
 150 
 151     public void setDataVector(Object[][] newData, Object[] columnIds) {
 152         checkDefaultTableModel();
 153         ((DefaultTableModel)getModel()).setDataVector(newData, columnIds);
 154     }
 155 
 156     protected void checkDefaultTableModel() {
 157         if(!(dataModel instanceof DefaultTableModel))
 158             throw new InternalError("In order to use this method, the data model must be an instance of DefaultTableModel.");
 159     }
 160 
 161 //
 162 //  Methods removed from JTable in the move from identifiers to ints.
 163 //
 164 
 165     public Object getValueAt(Object columnIdentifier, int rowIndex) {


< prev index next >