我正在使用 java swing 和 NetBeans 开发一个桌面应用程序它使用带有自定义表模型的 jtable 来呈现数据。我想在表格中显示最小行数,这样即使要显示的实际行数小于最小值,表格也应该显示额外的虚拟行以构成最小行数。
下面是表格模型的代码片段
public class MyTableModel extends AbstractTableModel {
private List<List<Object>> dataList = new ArrayList<>();
private String[] header = { "ID","SUBJECT","LETTTER FROM","LETTER DATE","DATE RECEIED",
"REMARKS","DATE DISPATCHED","DESTINATION OFFICE"};
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 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) {
return dataList.get(row).get(col);
}
@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;
}
}
任何可用的建议。