void (KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) return; for (TreePath path : paths) { if (path == null) continue; Object o = path.getLastPathComponent(); if (getTreeRoot() == o || getFile(o) == null) return; mySelectionManager.toggleSelection((DefaultMutableTreeNode)o); } myTree.revalidate(); myTree.repaint(); e.consume(); } }