I would like to add Cut
/ Copy
/ Paste
items into my context menu I already have available in my JTree
control.
I would like those actions just to initiate the default actions "cut", "copy", "paste" actions already implemented by the default JTree
, with as little boilerplate code as possible. I have checked the actions are available in the ActionMap on the tree, I can do getActionMap().get("cut") to get the corresponding action, but I do not know how to proceed - there is a method called SwingUtilities.notifyAction
(this is used when processing the default key bindings in the tree), but this method requires a few parameter values I do not have ready.
I expect the code could like a bit like this, only a different method needs to be used instead of notifyAction
, or perhaps some sensible values could be contstructed for missing parameters:
Action action = tree.getActionMap().get("cut");
if (action != null) {
SwingUtilities.notifyAction(action);
}