voici ma classe modele:
public class Model extends AbstractTableModel {
private final List<Source> sources = new ArrayList<Source>();
private final String[] entetes = {"SIT ","NO ","DATE", "HEURE ", "DATE ", "HEURE ", "DATE ","HEURE ", "TEMPS "};
public Model() {
super();
sources.add(new Source("", "", "", "", "","","","",""));
sources.add(new Source("", "", "","", "","","","",""));
sources.add(new Source("", "", "","", "","","","",""));
}
public int getRowCount() {
return sources.size();
}
public int getColumnCount() {
return entetes.length;
}
public String getColumnName(int columnIndex) {
return entetes[columnIndex];
}
public Object getValueAt(int rowIndex, int columnIndex) {
switch(columnIndex){
case 0:
return sources.get(rowIndex).getKom();
case 1:
return sources.get(rowIndex).getNir();
case 2:
return sources.get(rowIndex).getCot();
case 3:
return sources.get(rowIndex).setHor();
case 4:
return sources.get(rowIndex).getSp();
case 5 :
return sources.get(rowIndex).getHh();
case 6:
return sources.get(rowIndex).getDh();
case 7:
return sources.get(rowIndex).getDd();
case 8:
return sources.get(rowIndex).getTt();
default:
return null;
}
}
@Override
public Class getColumnClass(int columnIndex){
switch(columnIndex){
case 0:
return String.class;
case 1:
return String.class;
case 2:
return String.class;
case 3:
return String.class;
case 4 :
return String.class;
case 5:
return String.class;
case 6:
return String.class;
case 7:
return String.class;
default:
return Object.class;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if(aValue != null){
Source source = sources.get(rowIndex);
switch(columnIndex){
case 0:
source.setKom((String)aValue);
break;
case 1:
source.setNir((String)aValue);
break;
case 2:
source.setCot((String)aValue);
break;
case 3:
source.setHor((String)aValue);
break;
case 4:
source.setSp((String)aValue);
break;
case 5:
source.setHh((String)aValue);
case 6:
source.setDh((String)aValue);
case 7:
source.setTt((String)aValue);
}
}
}
public void addSource(Source source) {
sources.add(source);
fireTableRowsInserted(sources.size() -1, sources.size() -1);
}
public void removeSource(int rowIndex) {
sources.remove(rowIndex);
fireTableRowsDeleted(rowIndex, rowIndex);
}
aussi ma classe source:
public class Source {
private String nir;
private String kom;
private String cot;
private String hor;
private String sp;
private String hh;
private String dh;
private String dd;
private String tt;
public Source(String nir, String kom, String cot, String hor, String sp, String hh, String dh, String dd, String tt) {
super();
this.nir = nir;
this.kom = kom;
this.cot = cot;
this.hor = hor;
this.sp = sp;
this.hh = hh;
this.dh = dh;
this.dd = dd;
this.tt = tt;
}
public String getNir() {
return nir;
}
public void setNir(String nir) {
this.nir = nir;
}
public String getKom() {
return kom;
}
public void setKom(String kom) {
this.kom = kom;
}
public String getCot() {
return cot;
}
public void setCot(String cot) {
this.cot = cot;
}
public String setHor() {
return hor;
}
public void setHor(String hor) {
this.hor = hor;
}
public String getSp() {
return sp;
}
public void setSp(String sp) {
this.sp = sp;
}
public String getHh() {
return hh;
}
public void setHh(String hh) {
this.hh = hh;
}
public String getDh() {
return dh;
}
public void setDh(String dh) {
this.dh = dh;
}
public String getDd() {
return dd;
}
public void setDd(String dd) {
this.dd = dd;
}
public String getTt() {
return tt;
}
public void setTt(String tt) {
this.tt = tt;
}
}