File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes how can I disable cells in a table for selection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how can I disable cells in a table for selection?" Watch "how can I disable cells in a table for selection?" New topic
Author

how can I disable cells in a table for selection?

Nadin Jovan
Greenhorn

Joined: Aug 12, 2003
Posts: 7
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

Joined: Nov 04, 2002
Posts: 4
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

Joined: Aug 12, 2003
Posts: 7
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

Joined: Nov 04, 2002
Posts: 4
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;
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can I disable cells in a table for selection?