我有一个扩展java swing中的AbstrctTableModel类的TableModel类,但是当我试图初始化不抽象的子类时,Netbeans 8.0 IDE抱怨我正在初始化一个抽象类。代码片段如下:
public class TableModel extends AbstractTableModel {
private List<List<Object>> dataList = new ArrayList<>();
private String[] header = { "ID","SUBJECT","LETTTER FROM","LETTER DATE","DATE RECEIVED",
"REMARKS","DATE DISPATCHED","DESTINATION OFFICE"};
private int minRowCount = 5;
public TableModel()
{ }
public List<List<Object>> getDataList() {
return dataList;
}
public void setDataList(List<List<Object>> dataList) {
this.dataList = dataList;
fireTableDataChanged();
fireTableStructureChanged();
}
public void setHeader(String[] header) {
this.header = header;
}
public String[] getHeader() {
return header;
}
@Override
public int getRowCount() {
return Math.max(minRowCount, dataList.size());
}
@Override
public int getColumnCount() {
return header.length;
}
@Override
public String getColumnName(int col) {
return header[col];
}
@Override
public Object getValueAt(int row, int col) {
Object value = null;
if(row < dataList.size())
{value = dataList.get(row).get(col);}
return value;
}
@Override
public Class<?> getColumnClass(int column)
{
for (int row = 0; row < getRowCount(); row++)
{
Object o = getValueAt(row, column);
if (o != null)
{
return o.getClass();
}
}
return Object.class;
}
}
是初始化Table Model类的代码。
private TableColumnAdjuster tca;
/**
* Creates new form MyJFrame
*/
private TableModel tableModel ;
public MyJFrame() throws CorruptIndexException, LockObtainFailedException, IOException,
ParseException, java.text.ParseException, SQLException
{
tableModel = new TableModel(); // the Netbeans IDEcomplains about this code
initComponents();
}
您没有提供任何信息来指定投诉的确切性质,但我打赌AbstractTableModel
有一个您的TableModel
未能覆盖的抽象方法。在这种情况下,这将是一个编译错误。
如果这是真的,为这个方法提供一个具体的实现,你就可以进行下一步了