1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
//Un model 2 colonnes non éditables
DefaultTableModel model = new DefaultTableModel() {
boolean[] canEdit = new boolean[] { false, false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
};
// une table
JTable table = new JTable(model);
// un renderer
table.setDefaultRenderer(Object.class, renderer);
// mise a jour du model
model.addColumn("col1");
model.addColumn("col2");
//fonction d'ajout
public void addRecord(String s1, String s2) {
model.addRow(new Object[] { s1, s2});
} |
Partager