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
|
public class TableauQuestionTableModel extends AbstractTableModel
{
private ArrayList data = new ArrayList();
private String[] columnNames = new String[]{"Type", "Rang", "Code", "Libele", "Nombre"};
public void addNewRow(int ligne, String libelle, String code, String type)
{
if(data.size()==0)
{
data.add(0,new String[]{type, (new Integer(1)).toString(), code, libelle, (new Integer(0)).toString()});
}
else
{
data.add(ligne, new String[]{type, (new Integer(ligne+1)).toString(), code, libelle, (new Integer(0)).toString()});
}
this.fireTableStructureChanged();
}
public void removeNewRow(int ligne)
{
if (getRowCount() == 0 || ligne < 0)
return;
data.remove(ligne);
this.fireTableStructureChanged();
}
public int getColumnCount()
{
return columnNames.length;
}
public int getRowCount()
{
return data.size();
}
public String getColumnName(int col)
{
return columnNames[col];
}
public Object getValueAt(int row, int col)
{
String []o=(String[])data.get(row);
return o[col];
}
public Class getColumnClass(int c)
{
return getValueAt(0,c).getClass();
}
public boolean isCellEditable(int row, int col)
{return (col < 2);
}
public void setValueAt(String value, int row, int col)
{
String []o=(String[])data.get(row);
o[col]=value;
fireTableCellUpdated(row,col);
} |
Partager