This is how I get data from csv-file:
cSVFileReader = new CSVReader(new FileReader(sciezka), ','); // csv reader with coma-separator
java.util.List<String[]> myEntries = cSVFileReader.readAll();
String[][] rowData = myEntries.toArray(new String[0][]);
rowData = myEntries.toArray(new String[0][]);
columnnames = myEntries.get(0);
rowData = myEntries.toArray(new String[0][]);
DefaultTableModel tableModel = new DefaultTableModel(rowData, columnnames);
JTable table = new JTable(tableModel);
return table;
and this is how I count average:
public void getAverage() throws IOException{
CSVFile table = new CSVFile() ;
float sum = 0;
DefaultTableModel model = (DefaultTableModel) table.getModel();
int column = table.getSelectedColumn();
System.out.println(column); //show -1
rowcount = model.getRowCount();
System.out.println(rowcount); //show zero
}
I think, the problem is in wrong getting TableModel from JTable, but actually I can't understand how can I do it another way.