我一直试图展示JTable
,并且一直在制作奇怪的文物。
我有一个扩展AbstractTableModel
的课程。我不知道为什么我会收到这些文物。如何正确显示JTable
?
以下是我的TableModel
public class AllScansModel extends AbstractTableModel {
private List<WasScan> wasScans;
private String[] columns = new String[] { "Name", "Type", "Profile", "Date", "Status" };
public AllScansModel(List<WasScan> wasScans) {
this.wasScans = wasScans;
}
@Override
public int getRowCount() {
return wasScans.size();
}
@Override
public int getColumnCount() {
return columns.length;
}
public void setValueAt(int rowIndex, WasScan wasScan) {
wasScans.set(rowIndex, wasScan);
fireTableRowsUpdated(rowIndex, rowIndex);
}
public void addValue(WasScan wasScan){
wasScans.add(wasScan);
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
WasScan scan = wasScans.get(rowIndex);
switch (columnIndex) {
case 0:
return scan.getName().getValue();
case 1:
return scan.getType().toString();
case 2:
return scan.getProfile().getName().toString();
case 3:
return scan.getEndScanDate().toString();
case 4:
return scan.getStatus().toString();
}
return null;
}
@Override
public String getColumnName(int column) {
return columns[column];
}
public void updateTable(List<WasScan> wasScans) {
this.wasScans = wasScans;
fireTableDataChanged();
}
}