|
-
December 23rd, 2002, 10:48 AM
#1
URGENT JTable : deselect a cell at runtime
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.
-
December 23rd, 2002, 03:33 PM
#2
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:
Code:
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().
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|