这是我将表模型添加到表中的代码:
table = new JTable(new TerminiTableModel());
scrollPane = new JScrollPane(table);
然后我做了这个类TerminiTableModel(),这只是一个简单的生成代码,我想在其中获取列数和行数......列数工作得很好,并将3列添加到我的表中(“Termini”,“Ime i prezime ”和“纳波梅纳”)。当我在 getRowCount 中添加该行时,我得到错误,甚至无法编译它...这是代码...我对此进行了搜索,但无法弄清楚...:-/
public class TerminiTableModel extends AbstractTableModel implements TableModel {
protected TableModel tableModel;
private String[] columnNames = {"Termin", "Ime i prezime", "Napomena"};
private String[] data = {"7:00", "8:00", "9:00" , "10:00" , "11:00" , "12:00" };
@Override
public void addTableModelListener(TableModelListener arg0) {
// TODO Auto-generated method stub
}
@Override
public Class<?> getColumnClass(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public int getRowCount() {
return data.length; // <<----- this line is problem
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public Object getValueAt(int row, int col) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isCellEditable(int row, int col) {
if (col > 0) {
return true;
} else
return false;
}
@Override
public void removeTableModelListener(TableModelListener arg0) {
// TODO Auto-generated method stub
}
@Override
public void setValueAt(Object data, int row, int col) {
// TODO Auto-generated method stub
}
}
解决方案可能很简单,但我需要一些帮助......提前谢谢你......