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?
In addition to returning false
from isCellEditable()
, add these invocations.
table.setFocusable(false);
table.setRowSelectionAllowed(false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.