oceano22
oceano22

Reputation: 483

select all nodes in java tree

I would insert from right menu the option to select all the nodes of a tree. This functionality is implemented in standard pressing ctrl-a. How do I similura that functionality?

JTree tree = new JTree();

JPopupMenu popMenuTree = new JPopupMenu();
 JMenuItem selectAll = new JMenuItem();selectAll.setText("SelectAll");
    selectAll.setActionCommand("selectAll");

    KeyStroke ctrlXKeyStroke = KeyStroke.getKeyStroke("control A");
    selectAll.setAccelerator(ctrlXKeyStroke);
    popMenuTree.add(selectAll);

thank you so much

Upvotes: 0

Views: 184

Answers (1)

Juan Mellado
Juan Mellado

Reputation: 15113

Because popup menus, unlike regular menus, aren't always contained by a component, accelerators in popup menu items don't work unless the popup menu is visible.

Upvotes: 1

Related Questions