Class ButtonPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ButtonPanel extends JPanel
A reusable panel for buttons. The constructor takes an array of button labels and an optional action listener. The buttons are created and added to the panel, and the action listener is added to each button. The buttons can be enabled or disabled by index, or all at once by using index -1. The class also provides a static method for creating a button panel with combinations of OK, Cancel, Apply, and Delete buttons. Subclasses can override the userSetup() method to add additional components before the buttons are added.
See Also:
  • Field Details

    • USE_OK

      public static final int USE_OK
      Bit indicating using OK button
      See Also:
    • USE_CANCEL

      public static final int USE_CANCEL
      Bit indicating using Cancel button
      See Also:
    • USE_APPLY

      public static final int USE_APPLY
      Bit indicating using Apply button
      See Also:
    • USE_DELETE

      public static final int USE_DELETE
      Bit indicating using Delete button
      See Also:
    • USE_OKCANCEL

      public static final int USE_OKCANCEL
      Bit indicating using OK and Cancel buttons
      See Also:
    • USE_OKCANCELAPPLY

      public static final int USE_OKCANCELAPPLY
      Bit indicating using OK, Cancel, and Apply buttons
      See Also:
    • USE_OKCANCELDELETE

      public static final int USE_OKCANCELDELETE
      Bit indicating using OK, Cancel, and Delete buttons
      See Also:
    • OK_RESPONSE

      public static final int OK_RESPONSE
      Constant indicating an "ok" response
      See Also:
    • CANCEL_RESPONSE

      public static final int CANCEL_RESPONSE
      Constant indicating a "cancel" response
      See Also:
    • APPLY_RESPONSE

      public static final int APPLY_RESPONSE
      Constant indicating an "apply" response
      See Also:
    • DELETE_RESPONSE

      public static final int DELETE_RESPONSE
      Constant indicating a "delete" response
      See Also:
    • OK_LABEL

      public static final String OK_LABEL
      Constant string for "ok" label
      See Also:
    • CANCEL_LABEL

      public static final String CANCEL_LABEL
      Constant string for "cancel" label
      See Also:
    • APPLY_LABEL

      public static final String APPLY_LABEL
      Constant string for "apply" label
      See Also:
    • DELETE_LABEL

      public static final String DELETE_LABEL
      Constant string for "delete" label
      See Also:
    • buttons

      protected JButton[] buttons
      The buttons
    • labels

      protected String[] labels
      The labels
  • Constructor Details

    • ButtonPanel

      public ButtonPanel(String[] labels)
      The constructor.
      Parameters:
      labels - The button labels.
    • ButtonPanel

      public ButtonPanel(String[] labels, ActionListener alist)
      The constructor.
      Parameters:
      labels - The button labels.
      alist - Optional action listener.
    • ButtonPanel

      public ButtonPanel(String[] labels, ActionListener alist, int spacing)
      The constructor.
      Parameters:
      labels - The button labels.
      alist - Optional action listener.
      spacing - The spacing between labels.
    • ButtonPanel

      public ButtonPanel(String[] labels, ActionListener alist, int spacing, int alignment)
      The constructor.
      Parameters:
      labels - the button labels.
      alist - optional action listener.
      spacing - the spacing between labels.
      alignment - the layout alignment
  • Method Details

    • userSetup

      protected void userSetup()
      Place for subclasses to add something else
    • addButtons

      protected void addButtons(ActionListener alist)
      Add the buttons to the panel.
      Parameters:
      alist - An action listener.
    • setEnabled

      public void setEnabled(int index, boolean state)
      Enable or disable a button.
      Parameters:
      index - the index of the button. If -1, applies to all.
      state - if true, enable, else disable.
    • setToolTip

      public void setToolTip(int index, String tip)
      Set tooltip
      Parameters:
      index - The index of the button.
      tip - tooltip string
    • getInsets

      public Insets getInsets()
      Overrides:
      getInsets in class JComponent
    • closeOutPanel

      public static ButtonPanel closeOutPanel(int opt, ActionListener actionListener, int spacing)
      Makes a button panel with combinations of OK, Cancel, Apply, and Delete.
      Parameters:
      opt - Bitwise combination of USE_OK, USE_CANCEL, USE_APPLY, USE_DELETE
      actionListener - Action listener for button clicks
      spacing - The spacing between labels.