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
|
class MyTableModel extends AbstractTableModel {
private String[] columnNames={"hehehe","hohoho"};
private Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public void setColumnName(String[] colNames){
columnNames=new String[colNames.length];
columnNames=colNames;
}
public void setData(Object[][] data_){
data=data_;
}
public String getColumnName(int col) {
System.out.println("appele : renvoie '"+columnNames[col]+"'");
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
}
// -----------------
...
MyTableModel tm=new MyTableModel ();
JTable table = new JTable(tm);
JScrollPane table_sp=new JScrollPane(table);
panel_clients.add(table_sp);
String[] ti= {"huhu","hihi"};
tm_articles.setColumnName(ti);
table.revalidate(); |
Partager