I have a program that reads a CSV file (it's a table) using BufferedReader
which stores it in ArrayList
.
The column I want to sort according to is an integer value and i want to do it in ascending order. The column I want to use is column 2. I want the column to be sorted as soon as I open the jtable. I have tried using TableRowSorter but I want the table to automatically sort. Is there any other way of doing it. I have used AbstractTableModel
maybe I can input a code there.
Class MyModel extends AbstractTableModel {
private final String[] columnNames = { "Studentname" "Age" "Id"}
private Class[] columnClass = { String.class, Integer.class, Integer.class };
private ArrayList<String[]> Data = new ArrayList<String[]>();
public void AddCSVData(ArrayList<String[]> DataIn) {
this.Data = DataIn;
this.fireTableDataChanged();
}
@Override
public int getColumnCount() {
return columnNames.length;// length;
}
@Override
public int getRowCount() {
return Data.size();
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
public void setValueAt(Object aValue, int row, int col) {
Data.get(row)[col] = (String) aValue;
}
@Override
public Object getValueAt(int row, int col) {
return Data.get(row)[col];
}
}