Reputation: 476
I'm trying to create a JTable that simply displays data and does not allow any edits or selections. I set all cells to be uneditable by running:
TableModel model = new DefaultTableModel(data, titles) {
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
But I'm now trying to make all of the cells unselectable as well. I found the setRowSelectionAllowed
method which allowed me to disable the whole row being selected when a cell is selected, but that didn't stop the cell from being selectable. I looked through the methods of DefaultTableModel
but I didn't seen any isCellSelectable
method. Any suggestions?
Upvotes: 11
Views: 9827
Reputation: 205775
In addition to returning false
from isCellEditable()
, add these invocations.
table.setFocusable(false);
table.setRowSelectionAllowed(false);
Upvotes: 21