문제

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