final JXTree tree = new JXTree(); tree.expandAll(); final Action delegate = tree.getActionMap().get("selectNext"); Action action = new AbstractAction("navigateNonLeaf") { @Override public void actionPerformed(ActionEvent e) { boolean searching = true; while (searching) { TreePath old = tree.getLeadSelectionPath(); delegate.actionPerformed(e); TreePath path = tree.getLeadSelectionPath(); // nothing happened, back off if (areSame(old, path)) break; Object last = path.getLastPathComponent(); if (!tree.getModel().isLeaf(last)) { searching = false; } } } // TBD: implement "end of tree" private boolean areSame(TreePath old, TreePath path) { return path.equals(old); } }; tree.getActionMap().put("selectNext", action);
ActionMap map = getActionMap(); map.put("expand-all", new Actions("expand-all")); map.put("collapse-all", new Actions("collapse-all"));
ActionMap map = getActionMap(); map.put("expand-all", new Actions("expand-all")); map.put("collapse-all", new Actions("collapse-all"));
ActionMap map = getActionMap(); map.put("expand-all", new Actions("expand-all")); map.put("collapse-all", new Actions("collapse-all"));
ActionMap map = getActionMap(); map.put("expand-all", new Actions("expand-all")); map.put("collapse-all", new Actions("collapse-all"));
ActionMap map = getActionMap(); map.put("expand-all", new Actions("expand-all")); map.put("collapse-all", new Actions("collapse-all"));