void (KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { TreePath treePath = tree.getLeadSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath.getLastPathComponent(); toggleNode(tree, node); e.consume(); } }