Click to See Complete Forum and Search --> : URGENT JTable : deselect a cell at runtime


helenerom
December 23rd, 2002, 09:48 AM
Hi,

I need to deselect a cell at runtime (by clicking on a JButton) in a JTable and I can't managed to do it with isCellEditable()...

Does anybody have any idea how to do it ??
please help,
Thanks a lot by advance.

Hélène.

dlorde
December 23rd, 2002, 02:33 PM
I don't know of a simple way to deselect a single cell programmatically. As far as I know, you can only deselect whole rows and columns.

What you can do is fake it by using a TableCellRenderer that treats the cell in question as unselected and without focus, something like this:table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent (JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
// Use appropriate row & col values here
if (row == 2 && column == 2) {
isSelected = false;
hasFocus = false;
}
return super.getTableCellRendererComponent(table,
value, isSelected, hasFocus, row, column);

}
});Then you can ensure it won't be edited with isCellEditable().