Other problems occour if multiple value are selected:
1) If I select first the cell [2,3] and then the cell [4,5] the cell that is always visible after resorting is the cell [2,3], but if i click on the cell [2,3] anymore to get it the anchor then the table don't scroll at the end of the sort process.
2) If I disable the ContiguousCellSelection (pressing the F2 key on the example) and I select two or more rows, after the sorting the cell are correctly displayed (the row marked as selected are the right rows). The only question here is: why is displayed always the row selected with lowest row index? I think it's better to display the row with anchor. (Example to better understand: I select the row 2, 9, and 6. The row with anchor is the row 6. On ascending order is displayed the row that was in position 2, in the descending order is displayed the row that was in position 9)
The code to reproduce the problem is:
- Code: Select all
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import com.jidesoft.grid.SortableTable;
import com.jidesoft.swing.JideSwingUtilities;
public class JideSortTableBug {
public static void main(String[] args) {
JFrame d = new JFrame("JideSortTableBug");
SortableTable t = new SortableTable(new MyTableModel());
t.setNonContiguousCellSelection(true);
t.addKeyListener(new KeyAdapter(){
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_F2){
SortableTable src = (SortableTable) e.getSource();
src.setNonContiguousCellSelection(!src.isNonContiguousCellSelection());
System.out.println("nonContiguousCellselection "+(src.isNonContiguousCellSelection()?"enabled":"disabled"));
}
}
});
d.setContentPane(new JScrollPane(t));
d.pack();
JideSwingUtilities.globalCenterWindow(d);
d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
d.setVisible(true);
}
protected static class MyTableModel extends AbstractTableModel {
public int getRowCount() {
return 10000;
}
public int getColumnCount() {
return 9;
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return "" + rowIndex + "," + columnIndex;
}
}
}