galera, me ajudem por favor. eu estou tentando criar uma model prá minha jtable.
do jeito q está, mostra as linhas legal, mas o cabeçalho não aparece o q quero, aparece na coluna 1 “A”, coluna 2 “B”…
onde estou errando?
public class MyTableModel extends AbstractTableModel {
private List<Associate> lines = null;
private String[] cols = null;
public MyTableModel(List<Associate> lines, String[] cols) {
super();
this.setLines(lines);
this.setCols(cols);
}
/**
* @return the cols
*/
public String[] getCols() {
return cols;
}
/**
* @param cols the cols to set
*/
public void setCols(String[] cols) {
this.cols = cols;
}
/**
* @return the lines
*/
public List<Associate> getLines() {
return lines;
}
/**
* @param lines the lines to set
*/
public void setLines(List<Associate> lines) {
this.lines = lines;
}
public int getColumnCount() {
// TODO Auto-generated method stub
return this.getCols().length;
}
public int getRowCount() {
// TODO Auto-generated method stub
return this.getLines().size();
}
public Object getValueAt(int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
Associate a = this.getLines().get(rowIndex);
if (columnIndex==1) {
return a.getName();
}
if (columnIndex==0) {
return a.getId();
}
if (columnIndex==2) {
return a.getCoteNumber();
}
if (columnIndex==3) {
return a.getRg();
}
return null;
}
public void setValueAt(Object value, int row, int col) {
fireTableCellUpdated(row,col);
}
}
List<Associate> list = new DaoFactory().getAssociateDao().lista();
String[] cols = new String[] {"id", "nome", "rg", "cota"};
SearchAssociateForm s = new SearchAssociateForm();
TableModel model = new MyTableModel(list, cols);
s.setTableModel(model);