• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can I disable cells in a table for selection?

 
Nadin Jovan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table in which main diagonal should be disabled for selection
l s t
l X
s X
t X
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.
 
sheng wang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first, you should implemt a TableCellRender by youself.
and attention to method isCellEditable(int rowIndex, int columnIndex) in Interface TableModel
i think you can implement a TableModel by youself and only override the method.
soory. I am not good at english.
[ October 15, 2003: Message edited by: sheng wang ]
 
Nadin Jovan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you be more specific what do I need to do in the TableCellRenderer implementation? I can see that this interface has only one method.
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. I would like to disable them in some obvious and visible way, like when a CheckBox is disabled. Is that possible to do?
Thanks.
 
sheng wang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eg:
class SelfTableRender extends JCheckBox implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int column) {
/*
you can get Location by row, column
value is the value in table at current location
judge the value or location ...........
*/
setEnable(false);
setSelect(false);
..................
return this;
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic