Interacting with Swing

Action Adapters

There will be times when you need to interact with Swing's Action framework. ActionCommands provide Action adapters to support this case. To create an adaptor you simply call getActionAdapter(). You can also request an adapter for a specific face.

   ActionCommand command = ...;

   // create an adapter with the same properties as the default face
   Action adapter = command.getActionAdapter();
   // this adapter will have the same properties as the menu context
   Action menuAdapter = command.getActionAdapter(Face.MENU);

Installing Shortcuts

ActionCommands allow you to install shortcuts directly into components using the command accelerator. This mechanism automatically installs the appropriate entries into the input and action maps. This is useful for supporting accelerator keys for commands not contained within menus.

The following example installs the "control S" shortcut on a JPanel when ever it's contained within a focused window.

   # Command Config
   save@face.text=_Save@control S

   // Install the short cut
   JPanel panel = ...;
   ActionCommand command = new ActionCommand("save") {...};
   command.installShortCut(panel, JComponent.WHEN_IN_FOCUSED_WINDOW);