Originally posted by Oliver Brocker: ...But I want that the user cannot select any cell. So is there a way to disable the selectionmode? Unfortunately there is no NONE_SELECTION alternative.
You can do it in two ways: 1) Listen to row selections using a selection listener. On receiving the selection notifications, make a call to JTable#clearSelection 2) Provide renderers and tweak the selection background and selection foreground to be the same as the default background and foreground. Mind you in this case, any call to the table's selection model will return data as you are tweaking only the visual part and not touching the underlying selection model.
Originally posted by Oliver Brocker: On a javax.swing.JTable I can set the table's selection mode with setSelectionMode. Here I can set it to SINGLE_SELECTION, SINGLE_INTERVAL_SELECTION or MULTIPLE_INTERVAL_SELECTION.
But I want that the user cannot select any cell. So is there a way to disable the selectionmode? Unfortunately there is no NONE_SELECTION alternative.
yourTable.setSelectionModel( new NullSelectionModel() );
Note that cells may still be editable even though they can't be selected. [ July 24, 2008: Message edited by: Brian Cole ]
I take Maneesh Godbole's #1 proposal and it works fine for me. Maybe I will switch to another solution in the future. To set a NullSelectionModel is a nice idea. But first I try what happen with table.setEnabled(false) - I'm not sure if I already try it.
The right way to do is to use how Brian Cole said. Use his NUllSelectionModel. I think table.setEnabled() is not a fine idea. The problem is related to selection hence you should only fiddle with the selection model. Using table.setEnabled(false) will have so many side-effects...like editing is lost...events will be lsot...etc...
I guess there are couple of design issues in this classic software the GOD coded.