我想创建最初为空的JTable。然后,用户可以从CSV文件加载数据。因此,这意味着rowData
中的行数不为先验。我该如何更改此行Object rowData[][] = new Object[][]{};
以符合我的目标?
import javax.swing.table.AbstractTableModel;
class PaxListTableModel extends AbstractTableModel {
Object rowData[][] = new Object[][]{};
String columnNames[] = Constants.columnNamesPax;
public int getColumnCount() {
return columnNames.length;
}
public String getColumnName(int column) {
return columnNames[column];
}
public int getRowCount() {
return rowData.length;
}
public Object getValueAt(int row, int column) {
return rowData[row][column];
}
public Class getColumnClass(int column) {
return (getValueAt(0, column).getClass());
}
public void setValueAt(Object value, int row, int column) {
rowData[row][column] = value;
}
public boolean isCellEditable(int row, int column) {
return (column != 10);
}
}