⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e943. disabling selections in a jtable component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
The only way to completely prevent a selection in a JTable component is to prevent it from getting the focus using setFocusable(false). However, if you still need keystrokes to work in the component, this method is not an option. 
The next closest way to disable selections is to call setCellSelectionEnabled(false). After this call, isCellSelected() correctly returns false for every cell. However, getSelectedRows() and getSelectedColumns() do not return empty arrays as expected. Instead, the anchor cell (e944 Getting the Anchor Cell in a JTable Component) will be considered selected. Therefore, if you are using these methods, make sure you ignore the results if getCellSelectionEnabled() returns false. 

    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);
    
    // Do this only if there's no need for the component to have the focus
    table.setFocusable(false);
    
    // Partially disables selections (see description above)
    table.setCellSelectionEnabled(false);

 Related Examples 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -