Swing Action Delegates
SwingActionDelegates provide a convenience wrapper for integrating existing Swing Actions into GUI Commands delegate infrastructure. This is particularly useful when you need to create delegates from a component ActionMap.
The following example creates delegates for the cut, copy and paste actions of a JTextPane:
JTextPane textPane = new JTextPane(); // creates and binds add delegates for text pane cut, copy and // paste actions. SwingActionDelegate.bindAll(textPane, "cut-to-clipboard", "copy-to-clipboard", "paste-from-clipboard");
The above example binds the delegates back to the text pane with the same id as the Action. There are other methods that allow you to bind the delegates to a specific CommandContainer.
It's also possible to create delegates from scratch if you require greater control. The following example shows creating a delegate from an Action instance:
Action pasteAction = ...; SwingActionDelegate delegate = new SwingActionDelegate("paste", pasteAction); delegate.bind(...);