1 36 37 40 41 import java.lang.Thread ; 42 import java.util.*; 43 import java.awt.*; 44 import java.awt.event.*; 45 import javax.swing.*; 46 import javax.swing.event.*; 47 import javax.swing.plaf.*; 48 import javax.swing.table.*; 49 50 51 55 public class OldJTable extends JTable 56 { 57 61 public int getColumnIndex(Object identifier) { 62 return getColumnModel().getColumnIndex(identifier); 63 } 64 65 70 public TableColumn addColumn(Object columnIdentifier, int width) { 71 return addColumn(columnIdentifier, width, null, null, null); 72 } 73 74 public TableColumn addColumn(Object columnIdentifier, Vector columnData) { 75 return addColumn(columnIdentifier, -1, null, null, columnData); 76 } 77 78 public TableColumn addColumn(Object columnIdentifier, int width, 81 TableCellRenderer renderer, 82 TableCellEditor editor) { 83 return addColumn(columnIdentifier, width, renderer, editor, null); 84 } 85 86 public TableColumn addColumn(Object columnIdentifier, int width, 87 TableCellRenderer renderer, 88 TableCellEditor editor, Vector columnData) { 89 checkDefaultTableModel(); 90 91 DefaultTableModel m = (DefaultTableModel)getModel(); 93 m.addColumn(columnIdentifier, columnData); 94 95 TableColumn newColumn = new TableColumn(m.getColumnCount()-1, width, renderer, editor); 98 super.addColumn(newColumn); 99 return newColumn; 100 } 101 102 public void removeColumn(Object columnIdentifier) { 105 super.removeColumn(getColumn(columnIdentifier)); 106 } 107 108 public void addRow(Object [] rowData) { 109 checkDefaultTableModel(); 110 ((DefaultTableModel)getModel()).addRow(rowData); 111 } 112 113 public void addRow(Vector rowData) { 114 checkDefaultTableModel(); 115 ((DefaultTableModel)getModel()).addRow(rowData); 116 } 117 118 public void removeRow(int rowIndex) { 119 checkDefaultTableModel(); 120 ((DefaultTableModel)getModel()).removeRow(rowIndex); 121 } 122 123 public void moveRow(int startIndex, int endIndex, int toIndex) { 124 checkDefaultTableModel(); 125 ((DefaultTableModel)getModel()).moveRow(startIndex, endIndex, toIndex); 126 } 127 128 public void insertRow(int rowIndex, Object [] rowData) { 129 checkDefaultTableModel(); 130 ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData); 131 } 132 133 public void insertRow(int rowIndex, Vector rowData) { 134 checkDefaultTableModel(); 135 ((DefaultTableModel)getModel()).insertRow(rowIndex, rowData); 136 } 137 138 public void setNumRows(int newSize) { 139 checkDefaultTableModel(); 140 ((DefaultTableModel)getModel()).setNumRows(newSize); 141 } 142 143 public void setDataVector(Vector newData, Vector columnIds) { 144 checkDefaultTableModel(); 145 ((DefaultTableModel)getModel()).setDataVector(newData, columnIds); 146 } 147 148 public void setDataVector(Object [][] newData, Object [] columnIds) { 149 checkDefaultTableModel(); 150 ((DefaultTableModel)getModel()).setDataVector(newData, columnIds); 151 } 152 153 protected void checkDefaultTableModel() { 154 if(!(dataModel instanceof DefaultTableModel)) 155 throw new InternalError ("In order to use this method, the data model must be an instance of DefaultTableModel."); 156 } 157 158 162 public Object getValueAt(Object columnIdentifier, int rowIndex) { 163 return super.getValueAt(rowIndex, getColumnIndex(columnIdentifier)); 164 } 165 166 public boolean isCellEditable(Object columnIdentifier, int rowIndex) { 167 return super.isCellEditable(rowIndex, getColumnIndex(columnIdentifier)); 168 } 169 170 public void setValueAt(Object aValue, Object columnIdentifier, int rowIndex) { 171 super.setValueAt(aValue, rowIndex, getColumnIndex(columnIdentifier)); 172 } 173 174 public boolean editColumnRow(Object identifier, int row) { 175 return super.editCellAt(row, getColumnIndex(identifier)); 176 } 177 178 public void moveColumn(Object columnIdentifier, Object targetColumnIdentifier) { 179 moveColumn(getColumnIndex(columnIdentifier), 180 getColumnIndex(targetColumnIdentifier)); 181 } 182 183 public boolean isColumnSelected(Object identifier) { 184 return isColumnSelected(getColumnIndex(identifier)); 185 } 186 187 public TableColumn addColumn(int modelColumn, int width) { 188 return addColumn(modelColumn, width, null, null); 189 } 190 191 public TableColumn addColumn(int modelColumn) { 192 return addColumn(modelColumn, 75, null, null); 193 } 194 195 223 public TableColumn addColumn(int modelColumn, int width, 224 TableCellRenderer renderer, 225 TableCellEditor editor) { 226 TableColumn newColumn = new TableColumn(modelColumn, width, renderer, editor); 227 addColumn(newColumn); 228 return newColumn; 229 } 230 231 235 237 250 251 public boolean editColumnRow(int columnIndex, int rowIndex) { 252 return super.editCellAt(rowIndex, columnIndex); 253 } 254 255 public boolean editColumnRow(int columnIndex, int rowIndex, EventObject e){ 256 return super.editCellAt(rowIndex, columnIndex, e); 257 } 258 259 260 }
| Popular Tags
|