Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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});
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to divide coloumns in a text file into seperate arrays in java 
Java :: read CSV file and map it to bean java 
Java :: declare a variable java 
Java :: room ktx dependency 
Java :: Read array of characters from space separated values in java 
Java :: Java assertion with expression example 
Java :: java unfocus 
Java :: how to shorten if else if and else in java 
Java :: edit activity main drawer items text color android 
Java :: Dio.java 
Java :: produces 
Java :: cancel javafx stage exit request 
Java :: public class BigInteger { public static void main(String args[]) { long p=2147483648; } } 
Java :: code converter python to java 
Java :: check if object is a string java 
Java :: open bottomsheet from adapter java 
Java :: 2 multiples recursion 
Java :: java data table source tymeLeaf 
Java :: ban vs sri 
Java :: java decrypt CryptoJS 
Java :: binomial heap implementation java 
Java :: Second Activity not opening problem 
Java :: java setting logging with rotation logback 
Java :: ORM for Android 
Java :: java filter list of dupllicate netries 
Java :: Java Super Power java 
Java :: Java Protected Access Modifier package one 
Java :: Java object of the file 
Java :: Caused by: android.view.InflateException: Binary XML file line 
Java :: rotate matrix in java 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =