aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes disabling table cells for selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "disabling table cells for selection" Watch "disabling table cells for selection" New topic
Author

disabling table cells for selection

Nadin Jovan
Greenhorn

Joined: Aug 12, 2003
Posts: 7
I have a table in which main diagonal should be disabled for selection.
Users should be able to click on the remaining cells in order to turn them on or off. I would like to disable the main diagonal so that it is clear to the user that those cannot be changed.
What I did is, I created a subclass of the AbstractTableModel class and in that class I overwrote isCellEditable(int row, int column) method as follows:
public boolean isCellEditable(int row, int col) {
boolean result = (row >= 0 && col >= 1 && row != (col - 1));
return result;
}
So this will not allow user to modify cells on the main diagonal. However, these cells look the same as the rest of the cells in the table (they are always off and they cannot be modified). I would like to disable them in some obvious and visible way, like when a CheckBox is disabled. Is that possible to do?
Thanks.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

I'm just throwing this out there, but I think you have to extend JTable and override getCellRenderer(int, int). Then you need to implement javax.swing.table.TableCellRenderer or extend javax.swing.table.DefaultTableCellRenderer to make a DisabledCellRenderer. Use setBackground() and setForeground() in DisabledCellRenderer to make your disabled cells unique. In getCellRenderer() you can return DefaultTableCellRenderer for the active cells and DisabledCellRenderer for the disabled ones.


[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: disabling table cells for selection