void (KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { TreePath[] treePaths = tree.getSelectionPaths(); if (treePaths != null) { for (TreePath treePath : treePaths) { if (!isCheckboxEnabledFor(treePath, handler)) continue; handler.toggle(treePath, e); } e.consume(); } } }