1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
package jsl.table;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
public class SimpleTableModel extends AbstractTableModel{
private static final long serialVersionUID = 1;
private String[] columnNames = {};
private Class[] columnClass = {};
private ArrayList<ArrayList<Object>> data = new ArrayList<ArrayList<Object>>();
public SimpleTableModel(){
super();
}
public SimpleTableModel( ArrayList<ArrayList<Object>> dat, String[] cols, Class[] clas){
super();
update(dat,cols,clas);
}
public void setClasses(Class[] cla){
columnClass = cla;
}
public void empty(){
columnNames = new String[0];
data = new ArrayList<ArrayList<Object>>();
fireTableStructureChanged();
}
public void update( ArrayList<ArrayList<Object>> dat, String[] cols, Class[] clas){
columnClass = clas;
columnNames = cols;
data = dat;
fireTableStructureChanged();
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.size();
}
/** use with care, only to change column names */
public void setColumn(String[] column){
columnNames = column;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
ArrayList<Object> al = data.get(row);
return al.get(col);
}
public Class<?> getColumnClass(int c) {
return columnClass[c];
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void setValueAt(Object value, int row, int col) {
ArrayList<Object> al = data.get(row);
al.set(col, value);
data.set(row, al);
fireTableCellUpdated(row, col);
}
} |
Partager