0

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

oceano22
  • 463
  • 1
  • 5
  • 8

1 Answers1

1

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.

Juan Mellado
  • 14,973
  • 5
  • 47
  • 54