I am using Netbeans to develop an application that will be used in Windows. I noticed I can't right-click to copy or paste. How can I enable this? (I am using basic Swing controls such as JText and JTextArea.)
解决方案
I wouldn't create new copy, cut, paste, undo & select all actions, because those already exist inside the ActionMap of each component. I'd simply do:
Action copyAction = textField.getActionMap().get("copy");
Action cutAction = textField.getActionMap().get("cut");
Action pasteAction = textField.getActionMap().get("paste");
Action undoAction = textField.getActionMap().get("undo");
Action selectAllAction = textField.getActionMap().get("selectAll");
popup.add (undoAction);
popup.addSeparator();
popup.add (cutAction);
popup.add (copyAction);
popup.add (pasteAction);
popup.addSeparator();
popup.add (selectAllAction);
return popup;
That way you don't recreate more code that's already written. Other than that I'd follow that example.