I am having trouble implementing a JRadioButton
to sort a JList
of objects when a particular radio button is selected.
I have a custom Comparator
:
public class IDComparator implements Comparator<Object> {
public int compare(Object t, Object t1) {
return t.getId().compareTo(t1.getId());
}
}
Now I want to call that method onto the list of objects that I have in my frame to sort that list of objects.
I have tried something like...
private void jRadioButton1ActionPerformed(ActionEvent evt) {
if (jRadioButton1.isSelected()) {
Collections.sort(list, new IDComparator());
}
}
While implementing action listeners etc. but I think this is just sorting the list before it goes into the list(?). So it isn't much help to me.