Class ActionPanel
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
Adding actions - actions are grouped into action groups. Each action group will contain a header with the group name and a control button for expanding/collapsing the group. You can add actions one-by-one, or via addAll():
add(String groupName, EnhancedAction action)- adds a single action to the specified group.addAll(String groupName, List<EnhancedAction> actions)- adds multiple actions to the specified group.
The same action can be added to more than one group if desired. If the named group does not yet exist, it will be created.
Group names are case-insensitive; adding an action to group "File" is the same
as adding it to group "file" or "FILE". Group headers will be displayed using
the name as first specified when adding an action. Groups can be renamed
using setGroupName(String oldName, String newName), which does allow
you to change the case of a group.
Customizing action groups - you can associate an icon with an action group, and you can optionally specify a Comparator to control how actions within each group are sorted. By default, action groups have no icons, and actions are listed in the order in which they were added. To customize this:
setGroupIcon(String groupName, Icon icon)- sets the icon for the specified group.setGroupComparator(Comparator<String>>)- determines the order of action groups within the ActionPanel. By default, groups are presented in the order they were added.setActionComparator(Comparator<EnhancedAction> comparator)- sets the comparator for sorting actions within groups.
Styling options - methods are provided to customize fonts, colors, borders, and spacing for the ActionPanel as a whole, as well as for individual action groups. By default, the current Look and Feel defaults are applied. You can modify:
- Labels vs Buttons - use
setUseLabels()orsetUseButtons()to choose whether actions are presented as clickable JLabels or as JButtons. Default is JLabels. - Fonts - use
setActionFont()andsetGroupHeaderFont()to set fonts for actions and group headers, respectively. - Icons - if your actions have icons, they will be displayed next to the action name by default. You can disable this by calling setShowActionIcons(false). Group headers can also have icons, which can be set using setGroupIcon(). You can disable group icons with setShowGroupIcons(false).
- Colors - all colors are highly customizable. These options are found in the ColorOptions class, which you can access with getColorOptions(). Refer to ColorOptions class for more details.
- Borders - all borders are highly customizable. These options are found in the BorderOptions class, which you can access with getBorderOptions().Refer to BorderOptions class for more details.
- Spacing - you can control the spacing both within and around action groups:
use
setInternalPadding()to control the space between actions and the edges of the ActionPanel, and also between the actions themselves. UsesetExternalPadding()to control the space between action groups, and the space between action groups and the edge of the ActionPanel. - Expand/collapse state - the user can expand or collapse action groups by clicking
the button in the group header. All action groups are expanded initially by default.
Options related to group expansion and collapse are found in the ExpandCollapseOptions class,
which you can access with getExpandCollapseOptions().
Refer to the ExpandCollapseOptions class for more details on how to customize expand/collapse
behavior and animation.
You can listen for expand/collapse events with
addExpandListener(ExpandListener listener). - Expand/collapse button icons - by default, ActionPanel supplies built-in icons for use with
the expand/collapse button in each group header. These look like a + and - sign. You can supply
your own icons by calling
setExpandIcon(Icon icon)andsetCollapseIcon(Icon icon)on the ActionPanel. - Icon sizes - by default, all icons (header icons, action icons, and the icons for the
expand/collapse button) are rendered at 16x16 pixels. You can customize this size
using
setHeaderIconSize(int size)andsetActionIconSize(int size). The size applies to both width and height. Icons will be scaled as needed.
Toolbars - call setToolBarEnabled(true) to show a toolbar with each action group. The toolbar is highly configurable! There are built-in actions that allow you to support adding new actions to a group, renaming a group, reordering or removing items in a group, or removing groups. You can also supply custom actions to be displayed in the toolbar. Refer to ToolBarOptions for details on how to customize the toolbar and the actions it contains. Access the ToolBarOptions with getToolBarOptions().
Listening for events - there are a few notifications that callers can subscribe to:
- Expand/collapse events - listen for when the user expands or collapses an action group with
addExpandListener(ExpandListener listener). The listener will be notified of which group was expanded or collapsed, and whether it was an expand or a collapse event. - Group rename events - listen for when a group is renamed with
addGroupRenamedListener(GroupRenamedListener listener). The listener will be notified of the old and new group names. This listener is invoked both when the user renames a group via the toolbar (when group renaming is enabled) and when a group is renamed programmatically using methods such assetGroupName(String, String)orrenameGroup(String, String). - Group removal events - listen for when a group is removed with
addGroupRemovedListener(GroupRemovedListener listener). The listener will be notified of the name of the group that was removed. This listener is invoked both when the user removes a group via the toolbar (when group removal is enabled) and when a group is removed programmatically using methods such asremoveGroup(String). - Group reorder events - listen for when a group is reordered with
addGroupReorderedListener(GroupReorderedListener listener). The listener will be notified of the name of the group that was reordered. This listener is invoked both when the user reorders items via the toolbar (when reordering is enabled) and when the order is changed programmatically using methods such asreorderActions(String, int, int).
For a complete working example of ActionPanel with all customization options, refer to the demo application included with swing-extras! For more documentation and code examples, refer to the swing-extras book.
- Since:
- swing-extras 2.8
- Author:
- scorbo2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(String groupName, EnhancedAction action) Adds a single action to the specified group.A convenience method for adding a CardAction to this ActionPanel.addAll(String groupName, List<EnhancedAction> actions) Adds multiple actions to the specified group.addExpandListener(ExpandListener listener) You can listen for group expand/collapse events by adding an ExpandListener.addGroupRemovedListener(GroupRemovedListener listener) Subscribe to receive notification whenever a group is removed from this ActionPanel.addGroupRenamedListener(GroupRenamedListener listener) Subscribe to receive notification whenever a group is renamed within this ActionPanel.Subscribe to receive notification whenever the items within a group are reordered.clear(boolean pruneEmptyGroups) Removes all actions from all groups, and then optionally also removes all action groups that are empty.createEmptyGroup(String groupName) Creates an empty group with the given group name.voiddispose()Performs internal cleanup to ensure that this ActionPanel will become eligible for garbage collection when no longer needed.Returns the Comparator that is used to auto-sort the list of actions within each action group.Reports the component type that is used to represent actions.intReturns a total count of all actions in all action groups.intgetActionCount(String groupName) Returns the count of actions in the named group.Returns the font for action items.Returns the Margins instance for action groups.intReturns the size (width and height) at which action icons are rendered.intReturns the gap between the action icon and the action text.getActionsForGroup(String groupName) Returns all actions that belong to the specified group.Returns the Margins instance for the action tray area of action groups.We override to return our own stored background color.Options related to borders are accessed via the BorderOptions class.intReturns padding to add between button text/icons and the edges of the button.Returns the companion CardLayout Container instance, if one is set.Returns the icon used for the collapse button in action group headers.Options related to custom colors are accessed via the ColorOptions class.Options related to group expansion/collapse are accessed via the ExpandCollapseOptions class.Returns the icon used for the expand button in action group headers.intReturns the number of action groups in this ActionPanel.Returns the font for group headers.Returns a list of all group names in this ActionPanel.intReturns the size (width and height) at which header icons are rendered.Returns the Margins instance for the header area of action groups.Returns the Margins instance for the ToolBar.Options related to the ToolBar are accessed via the ToolBarOptions class.booleanhasAction(EnhancedAction action) Returns true if any action group contains the specified action.booleanReturns true if the named action exists within any action group.booleanhasAction(String groupName, EnhancedAction action) Returns true if the specified group contains the specified action.booleanReturns true if the specified group contains an action with the specified name.booleanReports whether a group with the given name exists in this ActionPanel.booleanReports whether auto-rebuild is enabled.booleanisExpanded(String groupName) Reports whether the named group is currently expanded.booleanisHighlightedAction(EnhancedAction action) Returns true if the given action is currently highlighted.booleanReports whether the last action to be executed in this ActionPanel should be visually highlighted.booleanReports whether action icons are shown next to action names.booleanReports whether group icons are shown next to group names.booleanReports whether the ToolBar is enabled.removeAction(EnhancedAction action) Removes all instances of the specified action from all action groups.removeAction(String actionName, boolean caseSensitive) Removes all instances of the named action from all action groups.removeAction(String groupName, EnhancedAction action) Removes the specified action from the named action group.removeAction(String groupName, String actionName, boolean actionNameCaseSensitive) Removes all instances of the named action from the named action group.removeExpandListener(ExpandListener listener) You can stop listening for group expand/collapse events by removing an ExpandListener.removeGroup(String groupName) Removes the specified action group entirely, along with all its actions.Stop listening for notification whenever a group is removed from this ActionPanel.Stop listening for notification whenever a group is renamed within this ActionPanel.Stop listening for notification whenever a group is reordered within this ActionPanel.booleanrenameGroup(String oldName, String newName) Attempts to rename the given group to the new name.setActionComparator(Comparator<EnhancedAction> comparator) Sets the comparator for sorting actions within action groups.Sets the component type that will be used to represent actions.setActionFont(Font font) Sets the font for action items.setActionIconSize(int size) Sets the size (width and height) at which action icons are rendered.setActionIconTextGap(int gap) Sets the gap between action icons and their text labels.setAutoRebuildEnabled(boolean enabled) Normally, ActionPanel will automatically rebuild itself whenever any option is modified.voidsetBackground(Color bg) We have to override this because we use a wrapper panel internally to manage our BoxLayout, so we need to store the background color and apply it to the wrapper panel during rebuild().setButtonPadding(int padding) Sets optional padding to add between button text/icons and the edges of the button.setCardContainer(Container container) Sets an optional companion CardLayout Container for this ActionPanel.setCollapseIcon(ImageIcon icon) Sets the icon to use for the collapse button in action group headers.setExpanded(String groupName, boolean expanded) Sets whether the named group is expanded or collapsed.setExpandIcon(ImageIcon icon) Sets the icon to use for the expand button in action group headers.setGroupComparator(Comparator<String> comparator) Sets the comparator for ordering action groups within the ActionPanel.setGroupHeaderFont(Font font) Sets the font for group headers.setGroupIcon(String groupName, Icon icon) Sets the icon for the specified group.setHeaderIconSize(int size) Sets the size (width and height) at which header icons are rendered.setHighlightedAction(EnhancedAction action) Sets the specified action as the currently highlighted action.setHighlightedAction(String cardId) If a companion CardLayout is linked, this will set the highlighted action to be the one that triggers the given cardId.setHighlightLastActionEnabled(boolean highlightLastAction) Enables or disables highlighting of the last action to be executed in this ActionPanel.setShowActionIcons(boolean showActionIcons) Controls whether action icons are shown next to action names.setShowGroupIcons(boolean showGroupIcons) Controls whether group icons are shown next to group names.setToolBarEnabled(boolean enabled) Enables or disables the ToolBar, which is shown at the bottom of each ActionGroup and contains buttons related to the actions in that group.Sets whether actions should be rendered as JButtons.Sets whether actions should be rendered as JLabels (clickable labels).toggleExpanded(String groupName) Toggles the expanded/collapsed state of the named group.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
DEFAULT_ICON_SIZE
public static final int DEFAULT_ICON_SIZE- See Also:
-
DEFAULT_INTERNAL_PADDING
public static final int DEFAULT_INTERNAL_PADDING- See Also:
-
DEFAULT_EXTERNAL_PADDING
public static final int DEFAULT_EXTERNAL_PADDING- See Also:
-
-
Constructor Details
-
ActionPanel
public ActionPanel()
-
-
Method Details
-
dispose
public void dispose()Performs internal cleanup to ensure that this ActionPanel will become eligible for garbage collection when no longer needed. -
add
Adds a single action to the specified group. If the group does not exist, it will be created. You can pass null for the action if you just want to create an empty group.- Parameters:
groupName- The name of the group to add the action to.action- The action to add. Can be null to just create the group if it does not exist.- Returns:
- This ActionPanel, for method chaining.
-
addAll
Adds multiple actions to the specified group. If the group does not exist, it will be created. The given list can be null or empty, in which case no actions are added to the group if it exists. But, an empty group will be created in that case if it does not already exist.- Parameters:
groupName- The name of the group to add the actions to.actions- The list of actions to add. Can be null or empty to just create the group if it does not exist.- Returns:
- This ActionPanel, for method chaining.
-
add
A convenience method for adding a CardAction to this ActionPanel. You must have already invoked setCardContainer() to set a companion CardLayout container! Otherwise, you will get an IllegalStateException.This method is shorthand for add(groupName, new CardAction(actionName, cardId));
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.
If the given actionName or the given cardId are null or blank, then the named group will be created if it does not exist, but no CardAction will be added to the group.
- Parameters:
groupName- The name of the group to which the new action should belong.actionName- The text for the action. Can be null to just create the named group.cardId- The id of the card to show when the action is triggered. Can be null to just create the group.- Returns:
- This ActionPanel, for method chaining.
-
getActionsForGroup
Returns all actions that belong to the specified group. If the named group does not exist, or does not contain any actions, then an empty list is returned. The actions are returned in the order determined by the action comparator for this ActionPanel, or in the order they were added if no comparator is set.- Parameters:
groupName- The name of the group whose actions should be returned. Case-insensitive.- Returns:
- A list of all actions that belong to the specified group.
-
createEmptyGroup
Creates an empty group with the given group name. If the named group already exists, this method does nothing (existing group contents are unchanged).- Parameters:
groupName- The name of the group to create.- Returns:
- This ActionPanel, for method chaining.
-
setCardContainer
Sets an optional companion CardLayout Container for this ActionPanel. If set, you can add CardActions to this ActionPanel, or you can use the convenience methods that accept a cardId parameter. When a CardAction is triggered, the specified card will be shown in the CardLayout container. You can pass null to disassociate any existing container, but note that if you have any CardActions in this ActionPanel, you must remove them first, or you will get an IllegalStateException.- Parameters:
container- Any Container with a CardLayout, or null to disassociate an existing container.- Returns:
- This ActionPanel, for method chaining.
-
getCardContainer
Returns the companion CardLayout Container instance, if one is set.- Returns:
- The CardLayout Container instance that is associated with this ActionPanel, or null if none is set.
-
isHighlightedAction
Returns true if the given action is currently highlighted.- Parameters:
action- The action to check.- Returns:
- True if the action is highlighted, false otherwise.
-
setHighlightedAction
If a companion CardLayout is linked, this will set the highlighted action to be the one that triggers the given cardId. If no such action is found, this does nothing. If no companion CardLayout is linked, you will receive an IllegalStateException.- Parameters:
cardId- The id of the card whose triggering action should be highlighted.- Returns:
- This ActionPanel, for method chaining.
-
setHighlightedAction
Sets the specified action as the currently highlighted action. Only one action can be highlighted at a time. Pass null to clear any highlighted action.- Parameters:
action- The action to highlight, or null to clear the highlighted action.- Returns:
- This ActionPanel, for method chaining.
-
isHighlightLastActionEnabled
public boolean isHighlightLastActionEnabled()Reports whether the last action to be executed in this ActionPanel should be visually highlighted. The default is false.- Returns:
- True if the last action is highlighted, false otherwise.
-
setHighlightLastActionEnabled
Enables or disables highlighting of the last action to be executed in this ActionPanel. The default is false.- Parameters:
highlightLastAction- True to enable highlighting of the last action, false to disable it.- Returns:
- This ActionPanel, for method chaining.
-
hasAction
Returns true if any action group contains the specified action.- Parameters:
action- The action to check for.- Returns:
- True if the action exists in any group, false otherwise.
-
hasAction
Returns true if the specified group contains the specified action. Group names are case-insensitive. If the named group does not exist in this action panel, false is returned (the group is not created).- Parameters:
groupName- The name of the group to check. Case-insensitive.action- The action to check for.- Returns:
- True if the action exists in the specified group, false otherwise.
-
hasAction
Returns true if the named action exists within any action group.- Parameters:
actionName- The name of the action to check for.caseSensitive- Whether the name comparison should be case-sensitive.- Returns:
- True if the action exists in any group, false otherwise.
-
hasAction
Returns true if the specified group contains an action with the specified name. Group names are case-insensitive. If the named group does not exist in this action panel, false is returned (the group is not created).- Parameters:
groupName- The name of the group to check. Case-insensitive.actionName- The name of the action to check for.actionNameCaseSensitive- Whether the action name comparison should be case-sensitive.- Returns:
- True if the action exists in the specified group, false otherwise.
-
removeAction
Removes all instances of the specified action from all action groups.- Parameters:
action- The action to remove.- Returns:
- This ActionPanel, for method chaining.
-
removeAction
Removes the specified action from the named action group. If the named group does not exist, no action is taken.- Parameters:
groupName- The name of the group to remove the action from.action- The action to remove.- Returns:
- This ActionPanel, for method chaining.
-
removeAction
Removes all instances of the named action from all action groups.- Parameters:
actionName- The name of the action to remove.caseSensitive- Whether the name comparison should be case-sensitive.- Returns:
- This ActionPanel, for method chaining.
-
removeAction
public ActionPanel removeAction(String groupName, String actionName, boolean actionNameCaseSensitive) Removes all instances of the named action from the named action group. If the named group does not exist, no action is taken. Group names are case-insensitive, but you can decide whether the action name comparison should be case-sensitive.- Parameters:
groupName- The name of the group to remove the action from. Case-insensitive.actionName- The name of the action to remove.actionNameCaseSensitive- Whether the name comparison should be case-sensitive.- Returns:
- This ActionPanel, for method chaining.
-
clear
Removes all actions from all groups, and then optionally also removes all action groups that are empty. -
getActionCount
public int getActionCount()Returns a total count of all actions in all action groups.- Returns:
- The total number of actions in this ActionPanel.
-
getActionCount
Returns the count of actions in the named group. Group names are case-insensitive.- Parameters:
groupName- The name of the group.- Returns:
- The number of actions in the specified group, or 0 if the group does not exist.
-
getGroupCount
public int getGroupCount()Returns the number of action groups in this ActionPanel.- Returns:
- The number of action groups.
-
hasGroup
Reports whether a group with the given name exists in this ActionPanel. Group names are case-insensitive.- Parameters:
groupName- The name of the group to check.- Returns:
- True if the group exists, false otherwise.
-
removeGroup
Removes the specified action group entirely, along with all its actions. If the named group does not exist, no action is taken. Group names are case-insensitive.- Parameters:
groupName- The name of the group to remove.- Returns:
- This ActionPanel, for method chaining.
-
renameGroup
Attempts to rename the given group to the new name. This may fail, if the old name does not reference any existing group. It may also fail if the given new name is already in use by another group. Group names are case-insensitive.- Parameters:
oldName- The current name of the group to rename. Case-insensitive.newName- The new name for the group. Case-insensitive. Cannot be null or empty.- Returns:
- True if the rename was successful, false otherwise (e.g. if oldName does not exist, or newName is already in use).
-
getGroupNames
Returns a list of all group names in this ActionPanel. The returned list will be sorted if we have a group comparator.- Returns:
- A list of all group names in this ActionPanel. May be empty.
-
setGroupIcon
Sets the icon for the specified group. If the named group does not exist, it is created.- Parameters:
groupName- The name of the group.icon- The icon to set.- Returns:
- This ActionPanel, for method chaining.
-
setActionComparator
Sets the comparator for sorting actions within action groups. By default, actions will be sorted in the order in which they were added to the group. You can pass null as the comparator to revert to the default behavior.- Parameters:
comparator- The comparator to use for sorting actions, or null for default order.- Returns:
- This ActionPanel, for method chaining.
-
getActionComparator
Returns the Comparator that is used to auto-sort the list of actions within each action group. If null, actions are presented in the order in which they were added to the group.- Returns:
- The Comparator used for sorting actions, or null if actions are presented in add order.
-
setGroupComparator
Sets the comparator for ordering action groups within the ActionPanel. By default, groups will be presented in the order in which they were added. You can pass null as the comparator to revert to the default behavior.- Parameters:
comparator- The comparator to use for sorting groups, or null for default order.- Returns:
- This ActionPanel, for method chaining.
-
setUseLabels
Sets whether actions should be rendered as JLabels (clickable labels). Shorthand for setActionComponentType(ActionComponentType.LABELS).- Returns:
- This ActionPanel, for method chaining.
-
setUseButtons
Sets whether actions should be rendered as JButtons. Shorthand for setActionComponentType(ActionComponentType.BUTTONS).- Returns:
- This ActionPanel, for method chaining.
-
setActionComponentType
Sets the component type that will be used to represent actions. You can use setUseButtons() or setUseLabels() as shorthand methods.- Parameters:
type- The ActionComponentType to use.- Returns:
- This ActionPanel, for method chaining.
-
getActionComponentType
Reports the component type that is used to represent actions.- Returns:
- The ActionComponentType in use.
-
setActionFont
Sets the font for action items. This overrides the Look and Feel default font. You can pass null to revert to the L&F default.- Parameters:
font- The font to use for actions, or null to use the L&F default.- Returns:
- This ActionPanel, for method chaining.
-
getActionFont
Returns the font for action items. May be null if Look and Feel defaults are in use.- Returns:
- The action font, or null if L&F default is in use.
-
setGroupHeaderFont
Sets the font for group headers. This overrides the Look and Feel default font. You can pass null to revert to the L&F default.- Parameters:
font- The font to use for group headers, or null to use the L&F default.- Returns:
- This ActionPanel, for method chaining.
-
getGroupHeaderFont
Returns the font for group headers. May be null if Look and Feel defaults are in use.- Returns:
- The group header font, or null if L&F default is in use.
-
getColorOptions
Options related to custom colors are accessed via the ColorOptions class. Developer note: yeah, they could all live here in this class, but this class is already unreasonably large, and there are many options related to color customization, so they were all moved over there. The only first-class color-related methods still in ActionPanel are setBackground() and getBackground(), which are overridden for internal reasons. All other color options are accessed via the ColorOptions instance returned by this method.- Returns:
- The ColorOptions instance containing options related to color customization.
-
getExpandCollapseOptions
Options related to group expansion/collapse are accessed via the ExpandCollapseOptions class. Developer note: yeah, they could all live here in this class, but this class is already unreasonably large, and there are many options related to expansion and collapse, so they were all moved over there.- Returns:
- The ExpandCollapseOptions instance containing options related to expansion and collapse.
-
getBorderOptions
Options related to borders are accessed via the BorderOptions class. Developer note: yeah, they could all live here in this class, but this class is already unreasonably large, and there are many options related to borders, so they were all moved over there.- Returns:
- The BorderOptions instance containing options related to border customization.
-
setBackground
We have to override this because we use a wrapper panel internally to manage our BoxLayout, so we need to store the background color and apply it to the wrapper panel during rebuild(). This is not at all obvious to callers, who may reasonably expect to be able to do actionPanel.setBackground(). So, we intercept it and do the right thing behind the scenes. All of our other color options are stored in our ColorOptions instance.Setting null here will revert to the Look and Feel default background color.
- Overrides:
setBackgroundin classJComponent- Parameters:
bg- the desired backgroundColor
-
getBackground
We override to return our own stored background color. If null was passed to setBackground(), this will return the Look and Feel default Panel background color.- Overrides:
getBackgroundin classComponent- Returns:
- the background
Colorof the ActionPanel itself.
-
getHeaderMargins
Returns the Margins instance for the header area of action groups. This controls the space between the header components (e.g. icon, label, expand/collapse button) and the edges of the header. The internalSpacing property controls the space between the header components themselves.Note: changing any of the properties of the returned Margins instance will trigger an immediate rebuild of the ActionPanel. If you have multiple changes you wish to make, it may make sense to disable auto-rebuild until after your changes are complete, to avoid unnecessary intermediate rebuilds. For example:
actionPanel.setAutoRebuild(false); try { Margins margins = actionPanel.getHeaderMargins(); margins.setTop(10); margins.setBottom(10); margins.setLeft(5); margins.setRight(5); } finally { // Re-enabling auto-rebuild will trigger // an immediate rebuild: actionPanel.setAutoRebuild(true); }- Returns:
- The Margins instance for the header area of action groups.
-
getActionTrayMargins
Returns the Margins instance for the action tray area of action groups. This controls the space between the action components (e.g. buttons/labels) and the edges of the action tray. The internalSpacing property controls the space between the action components themselves.Note: changing any of the properties of the returned Margins instance will trigger an immediate rebuild of the ActionPanel. If you have multiple changes you wish to make, it may make sense to disable auto-rebuild until after your changes are complete, to avoid unnecessary intermediate rebuilds. For example:
actionPanel.setAutoRebuild(false); try { Margins margins = actionPanel.getActionTrayMargins(); margins.setTop(10); margins.setBottom(10); margins.setLeft(5); margins.setRight(5); } finally { // Re-enabling auto-rebuild will trigger // an immediate rebuild: actionPanel.setAutoRebuild(true); }- Returns:
- The Margins instance for the action tray area of action groups.
-
getToolBarMargins
Returns the Margins instance for the ToolBar. This controls the space between the ToolBar buttons and the edges of the ToolBar area. If the ToolBar is not in Stretch mode, then the internalSpacing property controls the space between the ToolBar buttons themselves. If the ToolBar is in Stretch mode, then there is no space between the buttons, regardless of the internalSpacing setting, because the buttons are stretched to fill all available space.Note: changing any of the properties of the returned Margins instance will trigger an immediate rebuild of the ActionPanel. If you have multiple changes you wish to make, it may make sense to disable auto-rebuild until after your changes are complete, to avoid unnecessary intermediate rebuilds. For example:
actionPanel.setAutoRebuild(false); try { Margins margins = actionPanel.getToolBarMargins(); margins.setTop(10); margins.setBottom(10); margins.setLeft(5); margins.setRight(5); } finally { // Re-enabling auto-rebuild will trigger // an immediate rebuild: actionPanel.setAutoRebuild(true); }- Returns:
- The Margins instance for the ToolBar.
-
getActionGroupMargins
Returns the Margins instance for action groups. This controls the space between action groups and the edges of the ActionPanel. The internalSpacing property controls the gap between action groups themselves.Note: changing any of the properties of the returned Margins instance will trigger an immediate rebuild of the ActionPanel. If you have multiple changes you wish to make, it may make sense to disable auto-rebuild until after your changes are complete, to avoid unnecessary intermediate rebuilds. For example:
actionPanel.setAutoRebuild(false); try { Margins margins = actionPanel.getActionGroupMargins(); margins.setTop(10); margins.setBottom(10); margins.setLeft(5); margins.setRight(5); } finally { // Re-enabling auto-rebuild will trigger // an immediate rebuild: actionPanel.setAutoRebuild(true); }- Returns:
- The Margins instance for action groups.
-
getActionIconTextGap
public int getActionIconTextGap()Returns the gap between the action icon and the action text. This is only relevant if showActionIcons is true and actions have icons. Note we don't use the action tray's internalSpacing for this, because it's nice to be able to control this text gap separately from the gap between the action components themselves.- Returns:
- The gap in pixels between the action icon and the action text.
-
setActionIconTextGap
Sets the gap between action icons and their text labels. This is only relevant if showActionIcons is true and actions have icons. Note we don't use the action tray's internalSpacing for this, because it's nice to be able to control this text gap separately from the gap between the action components themselves.- Parameters:
gap- The gap in pixels between the action icon and the action text. Must be 0 or greater.- Returns:
- This ActionPanel, for method chaining.
-
setButtonPadding
Sets optional padding to add between button text/icons and the edges of the button. This applies to actions, when rendered as buttons, and also applies to toolbar buttons, if the toolbar is enabled. The default value is 2.- Parameters:
padding- A pixel value to apply between button text/icons and the edges of the button. Must be 0 or greater.- Returns:
- This ActionPanel, for method chaining.
-
getButtonPadding
public int getButtonPadding()Returns padding to add between button text/icons and the edges of the button. This applies to actions, when rendered as buttons, and also applies to toolbar buttons, if the toolbar is enabled. The default value is 2.- Returns:
- The pixel value of the padding between button text/icons and the edges of the button.
-
setHeaderIconSize
Sets the size (width and height) at which header icons are rendered. The default is 16 pixels. Icons will be scaled as needed.- Parameters:
size- The icon size in pixels. Must be greater than 0.- Returns:
- This ActionPanel, for method chaining.
-
getHeaderIconSize
public int getHeaderIconSize()Returns the size (width and height) at which header icons are rendered.- Returns:
- The header icon size in pixels.
-
setActionIconSize
Sets the size (width and height) at which action icons are rendered. The default is 16 pixels. Icons will be scaled as needed.- Parameters:
size- The icon size in pixels. Must be greater than 0.- Returns:
- This ActionPanel, for method chaining.
-
getActionIconSize
public int getActionIconSize()Returns the size (width and height) at which action icons are rendered.- Returns:
- The action icon size in pixels.
-
setExpandIcon
Sets the icon to use for the expand button in action group headers.- Parameters:
icon- The expand icon. Cannot be null.- Returns:
- This ActionPanel, for method chaining.
-
getExpandIcon
Returns the icon used for the expand button in action group headers.- Returns:
- The expand icon.
-
setCollapseIcon
Sets the icon to use for the collapse button in action group headers.- Parameters:
icon- The collapse icon. Cannot be null.- Returns:
- This ActionPanel, for method chaining.
-
getCollapseIcon
Returns the icon used for the collapse button in action group headers.- Returns:
- The collapse icon.
-
isShowActionIcons
public boolean isShowActionIcons()Reports whether action icons are shown next to action names. By default, if an action has an icon set, it will be shown next to the action name. You can disable this by calling setShowActionIcons(false). -
setShowActionIcons
Controls whether action icons are shown next to action names. By default, if an action has an icon set, it will be shown next to the action name. You can disable this by calling setShowActionIcons(false). -
isShowGroupIcons
public boolean isShowGroupIcons()Reports whether group icons are shown next to group names. By default, if a group has an icon set, it will be shown next to the group name. You can disable this by calling setShowGroupIcons(false). -
setShowGroupIcons
Controls whether group icons are shown next to group names. By default, if a group has an icon set, it will be shown next to the group name. You can disable this by calling setShowGroupIcons(false). -
isExpanded
Reports whether the named group is currently expanded. If the named group does not exist, returns false. Group names are case-insensitive.- Parameters:
groupName- The name of the action group.- Returns:
- True if the group is expanded, false if it is collapsed.
-
setExpanded
Sets whether the named group is expanded or collapsed. If the named group does not exist, does nothing. Group names are case-insensitive.- Parameters:
groupName- The name of the action group.expanded- True to expand the group, false to collapse it.- Returns:
- This ActionPanel, for method chaining.
-
toggleExpanded
Toggles the expanded/collapsed state of the named group. If the named group does not exist, does nothing. Group names are case-insensitive.- Parameters:
groupName- The name of the action group.- Returns:
- This ActionPanel, for method chaining.
-
isToolBarEnabled
public boolean isToolBarEnabled()Reports whether the ToolBar is enabled. When enabled, the ToolBar is shown at the bottom of each ActionGroup. It contains buttons related to the actions in that group. To configure the ToolBar, use the ToolBarOptions object accessible via getToolBarOptions().- Returns:
- True if the ToolBar is enabled, false otherwise.
-
setToolBarEnabled
Enables or disables the ToolBar, which is shown at the bottom of each ActionGroup and contains buttons related to the actions in that group. To configure the ToolBar, use the ToolBarOptions object accessible via getToolBarOptions().- Parameters:
enabled- True to enable the ToolBar, false to disable it.- Returns:
- This ActionPanel, for method chaining.
-
getToolBarOptions
Options related to the ToolBar are accessed via the ToolBarOptions class. Developer note: yeah, they could all live here in this class, but this class is already unreasonably large, and the ToolBar has a somewhat complicated setup, so they were all moved over there. The only first-class ToolBar option still in ActionPanel is isToolBarEnabled(), which is the master switch that controls whether the ToolBar is shown at all.- Returns:
- The ToolBarOptions instance containing options related to the ToolBar.
-
setAutoRebuildEnabled
Normally, ActionPanel will automatically rebuild itself whenever any option is modified. If you have multiple successive changes to make, and want to spare the thrashing of multiple rebuilds, you can disable auto-rebuild, make your changes, then re-enable auto-rebuild. Invoking setAutoRebuildEnabled(true) will immediately trigger a rebuild if auto-rebuild was previously disabled.- Parameters:
enabled- True to enable auto-rebuild, false to disable it.- Returns:
- This ActionPanel, for method chaining.
-
isAutoRebuildEnabled
public boolean isAutoRebuildEnabled()Reports whether auto-rebuild is enabled. When enabled, ActionPanel will automatically rebuild itself whenever any option is modified. When disabled, ActionPanel will not rebuild itself until setAutoRebuildEnabled(true) is invoked.- Returns:
- True if auto-rebuild is enabled, false otherwise.
-
addExpandListener
You can listen for group expand/collapse events by adding an ExpandListener. -
removeExpandListener
You can stop listening for group expand/collapse events by removing an ExpandListener. -
addGroupRenamedListener
Subscribe to receive notification whenever a group is renamed within this ActionPanel.- Parameters:
listener- A GroupRenamedListener to be notified whenever a group is renamed within this ActionPanel.- Returns:
- This ActionPanel, for method chaining.
-
removeGroupRenamedListener
Stop listening for notification whenever a group is renamed within this ActionPanel.- Parameters:
listener- A GroupRenamedListener that was previously registered to receive notification of group renames.- Returns:
- This ActionPanel, for method chaining.
-
addGroupRemovedListener
Subscribe to receive notification whenever a group is removed from this ActionPanel.- Parameters:
listener- A GroupRemovedListener to be notified whenever a group is removed from this ActionPanel.- Returns:
- This ActionPanel, for method chaining.
-
removeGroupRemovedListener
Stop listening for notification whenever a group is removed from this ActionPanel.- Parameters:
listener- A GroupRemovedListener that was previously registered to receive notification of group removals.- Returns:
- This ActionPanel, for method chaining.
-
addGroupReorderedListener
Subscribe to receive notification whenever the items within a group are reordered. This happens from the built-in group edit dialog, where the user can drag-and-drop to manually reorder items, or use the sort options on the dialog. Callers will NOT receive notifications when action groups are sorted by a provided Comparator. This subscription event is only for manual user-driven reordering.Note that at any time, you can invoke getActionsForGroup() to get the ordered list of actions for a given group. So, if you have a Comparator set, you have an easy way of discovering the auto-sorted order.
- Parameters:
listener- A GroupReorderedListener to be notified whenever the items within a group are reordered.- Returns:
- This ActionPanel, for method chaining.
-
removeGroupReorderedListener
Stop listening for notification whenever a group is reordered within this ActionPanel.- Parameters:
listener- A GroupReorderedListener that was previously registered to receive notification of group reordering.- Returns:
- This ActionPanel, for method chaining.
-