Class CardAction

All Implemented Interfaces:
ActionListener, Serializable, Cloneable, EventListener, Action

public class CardAction extends EnhancedAction
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 Details

    • cardId

      protected final String cardId
    • cardContainer

      protected Container cardContainer
  • Constructor Details

    • CardAction

      public CardAction(String name, String cardId)
      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

      public CardAction(String name, String cardId, Icon icon)
      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

      public void actionPerformed(ActionEvent e)