简体   繁体   English

选择Java树中的所有节点

[英]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. 此功能在标准按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 非常感谢

由于弹出菜单与常规菜单不同,并不总是包含在组件中,因此除非可见弹出菜单,否则弹出菜单项中的加速器将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM