Package ca.corbett.extras.actionpanel
Class CardAction
java.lang.Object
javax.swing.AbstractAction
ca.corbett.extras.EnhancedAction
ca.corbett.extras.actionpanel.CardAction
- All Implemented Interfaces:
ActionListener,Serializable,Cloneable,EventListener,Action
An action that flips to a specific card in a CardLayout when triggered.
You can create these manually and add them to an ActionPanel, or you can
use the convenience method in ActionPanel to create them for you.
The following two approaches are equivalent:
// Given some card container and an actionPanel...
cardContainer.setLayout(new CardLayout());
cardContainer.add(new JPanel(), "card1");
actionPanel = new ActionPanel();
// First, associate the Card Container with the ActionPanel:
actionPanel.setCardContainer(cardContainer);
// Option 1: create a CardAction manually:
CardAction action = new CardAction("Show Card 1", "card1");
actionPanel.add("Group 1", action);
// Option 2: let ActionPanel do it for you:
actionPanel.add("Group 1", "Show Card 1", "card1");
// In both cases, ActionPanel will let the CardAction know
// about the Card Container. You don't have to manually associate that.
- Since:
- swing-extras 2.8
- Author:
- scorbo2
- See Also:
-
Field Summary
FieldsFields inherited from class javax.swing.AbstractAction
changeSupport, enabledFields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON -
Constructor Summary
ConstructorsConstructorDescriptionCardAction(String name, String cardId) Creates a CardAction with the given name and card ID.CardAction(String name, String cardId, Icon icon) Creates a CardAction with the given name, card ID, and icon. -
Method Summary
Methods inherited from class ca.corbett.extras.EnhancedAction
getAcceleratorKey, getDescription, getIcon, getName, getTooltip, setAcceleratorKey, setDescription, setIcon, setName, setTooltipMethods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
Field Details
-
cardId
-
cardContainer
-
-
Constructor Details
-
CardAction
Creates a CardAction with the given name and card ID. The card ID is the name of the card to show when this action is triggered.Note: Due to the design of CardLayout, we can't validate the given cardId. If it doesn't match the name of a card that was given to your layout, then nothing will happen when the action is triggered. It's up to calling code to make sure the cardId given here matches the name of a card in the card container.
- Parameters:
name- the name of this action (e.g. the text to show on a button)cardId- the name of the card to show when this action is triggered. This should match the name of a card in the card container's CardLayout.
-
CardAction
Creates a CardAction with the given name, card ID, and icon. The card ID is the name of the card to show when this action is triggered.Note: Due to the design of CardLayout, we can't validate the given cardId. If it doesn't match the name of a card that was given to your layout, then nothing will happen when the action is triggered. It's up to calling code to make sure the cardId given here matches the name of a card in the card container.
- Parameters:
name- the name of this action (e.g. the text to show on a button)cardId- the name of the card to show when this action is triggered. This should match the name of a card in the card container's CardLayout.icon- the icon to show for this action (e.g. on a button). This can be null if you don't want an icon.
-
-
Method Details
-
actionPerformed
-