I have a RowSorterListener. I would like to be able to tell which column fires the RowSorterEvent. However when I attempt to get the column, I do not get the output I desire.
public class CustomRowSorterListener implements RowSorterListener {
JTable table;
public CustomRowSorterListener(JTable table) {
this.table = table;
}
@Override
public void sorterChanged(RowSorterEvent e)
{
//Attempt 1
System.out.println(e.getSource()); //Returns RowSorter and not a column
//Attempt 2
System.out.println(e.getSource().getColumn()); //Caused error in code
//Attempt 3
System.out.println(table.getColumn()) //Didn't work because no arguments were
//provided. However, I was unsure if it could
//be done this way.
//System.out.println(table.getColumn(e.getSource())) also doesn't work
}
}
I would appreciate any help in getting a solution which works.
Start with the
SortKey. It can returngetColumn. For example: