Answers for "DefaultTablemodel column sum"

0

how do i get DefaultTableModel rows sum in column in java

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});
}
Posted by: Guest on August-26-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language