简体   繁体   English

将所有JTable单元格设置为不可选择

[英]Set all JTable cells unselectable

I'm trying to create a JTable that simply displays data and does not allow any edits or selections. 我正在尝试创建一个仅显示数据且不允许进行任何编辑或选择的JTable。 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. 我找到了setRowSelectionAllowed方法,该方法使我可以在选择单元格时禁用整个行的选择,但这并没有阻止该单元格被选择。 I looked through the methods of DefaultTableModel but I didn't seen any isCellSelectable method. 我浏览了DefaultTableModel的方法,但没有看到任何isCellSelectable方法。 Any suggestions? 有什么建议么?

In addition to returning false from isCellEditable() , add these invocations. 除了从isCellEditable()返回false isCellEditable() ,还添加这些调用。

table.setFocusable(false);
table.setRowSelectionAllowed(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM