質問

What I'm trying to do is to prevent Cut/Copy/Paste on a JTree, because I want all node-moving to be done via drag and drop.

Copy and Paste are already prevented in the canImport and importData methods of the handler, but I can't think how to prevent Cut.

In addition, all these didn't work:

Tree.getActionMap().put( "cut", null );

InputMap inputMap = Tree.getInputMap(JComponent.WHEN_FOCUSED);
inputMap.put(KeyStroke.getKeyStroke('X', java.awt.event.InputEvent.CTRL_MASK), null);

ActionMap actionMap = Tree.getActionMap();
actionMap.put("cut", null);
役に立ちましたか?

解決

This works for me:

ActionMap actionMap = tree.getActionMap();
actionMap.remove("cut");
actionMap.getParent().remove("cut");
actionMap.remove("copy");
actionMap.getParent().remove("copy");
actionMap.remove("paste");
actionMap.getParent().remove("paste");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top