📌  相关文章
📜  如何在 java 代码示例中的列中获取 DefaultTableModel 行总和

📅  最后修改于: 2022-03-11 14:52:37.639000             🧑  作者: Mango

代码示例1
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});
}