JTable: Clicking from editable to non-editable cells.
Hi, I think JTable (or more accurately the selection model) isn't detecting changes in selection when I click from editable to non-editable fields. If you run the code below you'll notice that if you click from an editable cell to a non-editable cell the selection isn't being picked up by the ListSelectionListener. Is this a bug? Otherwise, I'd love an explanation as to what's gonig on.
Thanks.
class TestTable
{
publicstaticvoid main(String[] args)
{
final JTable table =new JTable(10, 6)
{
publicboolean isCellEditable(int r,int c)
{
return c % 2 == 0;
}
};
((DefaultCellEditor)table.getDefaultEditor(String.class)).setClickCountToStart(1);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setCellSelectionEnabled(true);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener()
{
publicvoid valueChanged(ListSelectionEvent e)
{
if (e.getValueIsAdjusting())
return;
System.out.println("selected(r, c) = "+table.getSelectedRow()+","+table.getSelectedColumn());
}
});
JDialog d =new JDialog();
d.add(new JScrollPane(table));
d.pack();
d.setVisible(true);
}
}

