📅  最后修改于: 2022-03-11 14:52:37.639000             🧑  作者: Mango
jTable1.setColumnSelectionAllowed(true);
jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
public void calculate() {
calculate(jTable1, jTable1.getSelectedColumn(), jTable1.getSelectedRows());
}
public void calculate(JTable table, int column, int[] rows) {
int result = 0;
for (int row : rows) {
result += Integer.valueOf(table.getValueAt(row, column).toString());
}
((DefaultTableModel) table.getModel()).addRow(new Object[]{result});
}