how do i get defaulttablemodel rows sum in column in java

Solutions on MaxInterview for how do i get defaulttablemodel rows sum in column in java by the best coders in the world

showing results for - "how do i get defaulttablemodel rows sum in column in java"
Alexa
28 Jan 2019
1jTable1.setColumnSelectionAllowed(true);
2jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
3
4
5
6public void calculate() {
7    calculate(jTable1, jTable1.getSelectedColumn(), jTable1.getSelectedRows());
8}
9
10public void calculate(JTable table, int column, int[] rows) {
11    int result = 0;
12    for (int row : rows) {
13        result += Integer.valueOf(table.getValueAt(row, column).toString());
14    }
15    ((DefaultTableModel) table.getModel()).addRow(new Object[]{result});
16}