Class JCommandButtonPanel
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,Scrollable
- Direct Known Subclasses:
AbstractFileViewPanel
,JRibbonApplicationMenuPopupPanelSecondary
Under the default JCommandButtonPanel.LayoutKind.ROW_FILL
, the buttons are laid out in
rows, never exceeding the available horizontal space. A vertical scroll bar
will kick in once there is not enough vertical space to show all the buttons.
The schematic below shows a row-fill command button panel:
+-----------------------------+-+ | | | | +----+ +----+ +----+ +----+ | | | | 01 | | 02 | | 03 | | 04 | | | | +----+ +----+ +----+ +----+ | | | | | | +----+ +----+ +----+ +----+ | | | | 05 | | 06 | | 07 | | 07 | | | | +----+ +----+ +----+ +----+ | | | | | | +----+ +----+ +----+ +----+ | | | | 09 | | 10 | | 11 | | 12 | | | | +----+ +----+ +----+ +----+ | | | | | | +----+ +----+ +----+ +----+ | | | | 13 | | 14 | | 15 | | 16 | | | +-----------------------------+-+
Each row hosts four buttons, and the vertical scroll bar allows scrolling the content down.
Under the JCommandButtonPanel.LayoutKind.COLUMN_FILL
, the buttons are laid out in
columns, never exceeding the available vertical space. A horizontal scroll
bar will kick in once there is not enough horizontal space to show all the
buttons. The schematic below shows a column-fill command button panel:
+---------------------------------+ | | | +----+ +----+ +----+ +----+ +---| | | 01 | | 04 | | 07 | | 10 | | 13| | +----+ +----+ +----+ +----+ +---| | | | +----+ +----+ +----+ +----+ +---| | | 02 | | 05 | | 08 | | 11 | | 14| | +----+ +----+ +----+ +----+ +---| | | | +----+ +----+ +----+ +----+ +---| | | 03 | | 06 | | 09 | | 12 | | 15| | +----+ +----+ +----+ +----+ +---| | | +---------------------------------+ +---------------------------------+
Each column hosts three buttons, and the horizontal scroll bar allows scrolling the content down.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enumerates the available layout kinds.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CommandToggleButtonGroup
The button group for the single selection mode.protected List
<List<AbstractCommandButton>> List of all button groups.protected int
Current icon dimension.protected CommandButtonDisplayState
Current icon state.List of titles for all button groups.protected boolean
Indicates the selection mode for theJCommandToggleButton
in this panel.protected JCommandButtonPanel.LayoutKind
Layout kind of this button panel.protected int
Maximum number of columns for this panel.protected int
Maximum number of rows for this panel.protected boolean
Iftrue
, the panel will show group labels.static final String
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a new panel.JCommandButtonPanel
(int startingDimension) Creates a new panel.JCommandButtonPanel
(CommandButtonDisplayState startingState) Creates a new panel. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addButtonGroup
(String buttonGroupName) Adds a new button group after all the existing button groups.void
addButtonGroup
(String buttonGroupName, int groupIndex) Adds a new button group at the specified index.int
addButtonToGroup
(String buttonGroupName, int indexInGroup, AbstractCommandButton commandButton) Adds a new button to the specified button group.int
addButtonToGroup
(String buttonGroupName, AbstractCommandButton commandButton) Adds a new button to the specified button group.int
addButtonToLastGroup
(AbstractCommandButton commandButton) Adds a new button to the specified button group.void
Adds the specified change listener to this button panel.protected void
Notifies all registered listener that the state of this command button panel has changed.int
Returns the number of buttons in this panel.getGroupButtons
(int groupIndex) Returns the list of all buttons in the specified button group.int
Returns the number of button groups in this panel.getGroupTitleAt
(int index) Returns the title of the button group at the specified index.Returns the layout kind of this panel.int
Returns the maximum button columns for this panel.int
Returns the maximum button rows for this panel.int
getScrollableBlockIncrement
(Rectangle visibleRect, int orientation, int direction) boolean
boolean
int
getScrollableUnitIncrement
(Rectangle visibleRect, int orientation, int direction) Returns the selected button of this panel.boolean
Returns indication whether button group labels should be shown.void
Removes all the button groups and buttons from this panel.void
removeButtonFromGroup
(String buttonGroupName, int indexInGroup) Removes the button at the specified index from the specified button group.void
removeButtonGroup
(String buttonGroupName) Removes the specified button group.void
Removes the specified change listener from this button panel.void
setIconDimension
(int dimension) Sets the new dimension for the icons in this panel.void
Sets the new state for the icons in this panel.void
setLayoutKind
(JCommandButtonPanel.LayoutKind layoutKind) Sets the new layout kind for this panel.void
setMaxButtonColumns
(int maxButtonColumns) Sets the maximum button columns for this panel.void
setMaxButtonRows
(int maxButtonRows) Sets the maximum button rows for this panel.void
setSingleSelectionMode
(boolean isSingleSelectionMode) Sets the selection mode for this panel.void
setToShowGroupLabels
(boolean toShowGroupLabels) Sets indication whether button group labels should be shown.void
updateUI()
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, paramString, setUI
Methods 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, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods 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, validateTree
Methods 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, getBackground, 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
-
uiClassID
- See Also:
-
groupTitles
List of titles for all button groups.- See Also:
-
buttons
List of all button groups.- See Also:
-
maxButtonColumns
protected int maxButtonColumnsMaximum number of columns for this panel. Relevant only when the layout kind isJCommandButtonPanel.LayoutKind.ROW_FILL
.- See Also:
-
maxButtonRows
protected int maxButtonRowsMaximum number of rows for this panel. Relevant only when the layout kind isJCommandButtonPanel.LayoutKind.COLUMN_FILL
.- See Also:
-
isSingleSelectionMode
protected boolean isSingleSelectionModeIndicates the selection mode for theJCommandToggleButton
in this panel.- See Also:
-
toShowGroupLabels
protected boolean toShowGroupLabelsIftrue
, the panel will show group labels.- See Also:
-
buttonGroup
The button group for the single selection mode. -
currDimension
protected int currDimensionCurrent icon dimension. -
currState
Current icon state. -
layoutKind
Layout kind of this button panel.- See Also:
-
-
Constructor Details
-
JCommandButtonPanel
protected JCommandButtonPanel()Creates a new panel. -
JCommandButtonPanel
public JCommandButtonPanel(int startingDimension) Creates a new panel.- Parameters:
startingDimension
- Initial dimension for buttons.
-
JCommandButtonPanel
Creates a new panel.- Parameters:
startingState
- Initial state for buttons.
-
-
Method Details
-
addButtonGroup
Adds a new button group at the specified index.- Parameters:
buttonGroupName
- Button group name.groupIndex
- Button group index.- See Also:
-
addButtonGroup
Adds a new button group after all the existing button groups.- Parameters:
buttonGroupName
- Button group name.- See Also:
-
removeButtonGroup
Removes the specified button group.- Parameters:
buttonGroupName
- Name of the button group to remove.- See Also:
-
addButtonToLastGroup
Adds a new button to the specified button group.- Parameters:
commandButton
- Button to add.- Returns:
- Returns the index of the button on the specified group, or -1 if no such group exists.
- See Also:
-
addButtonToGroup
Adds a new button to the specified button group.- Parameters:
buttonGroupName
- Name of the button group.commandButton
- Button to add.- Returns:
- Returns the index of the button on the specified group, or -1 if no such group exists.
- See Also:
-
addButtonToGroup
public int addButtonToGroup(String buttonGroupName, int indexInGroup, AbstractCommandButton commandButton) Adds a new button to the specified button group.- Parameters:
buttonGroupName
- Name of the button group.indexInGroup
- Index of the button in group.commandButton
- Button to add.- Returns:
- Returns the index of the button on the specified group, or -1 if no such group exists.
- See Also:
-
removeButtonFromGroup
Removes the button at the specified index from the specified button group.- Parameters:
buttonGroupName
- Name of the button group.indexInGroup
- Index of the button to remove.- See Also:
-
removeAllGroups
public void removeAllGroups()Removes all the button groups and buttons from this panel.- See Also:
-
getGroupCount
public int getGroupCount()Returns the number of button groups in this panel.- Returns:
- Number of button groups in this panel.
-
getButtonCount
public int getButtonCount()Returns the number of buttons in this panel.- Returns:
- Number of buttons in this panel.
-
getGroupTitleAt
Returns the title of the button group at the specified index.- Parameters:
index
- Button group index.- Returns:
- Title of the button group at the specified index.
-
updateUI
public void updateUI() -
getUIClassID
- Overrides:
getUIClassID
in classJPanel
-
setMaxButtonColumns
public void setMaxButtonColumns(int maxButtonColumns) Sets the maximum button columns for this panel. When this panel is shown and the layout kind isJCommandButtonPanel.LayoutKind.ROW_FILL
, it will have no more than this number of buttons in each row. Fires amaxButtonColumns
property change event.- Parameters:
maxButtonColumns
- Maximum button columns for this panel.- See Also:
-
getMaxButtonColumns
public int getMaxButtonColumns()Returns the maximum button columns for this panel. The return value is relevant only when the layout kind isJCommandButtonPanel.LayoutKind.ROW_FILL
.- Returns:
- Maximum button columns for this panel.
- See Also:
-
setMaxButtonRows
public void setMaxButtonRows(int maxButtonRows) Sets the maximum button rows for this panel. When this panel is shown and the layout kind isJCommandButtonPanel.LayoutKind.COLUMN_FILL
, it will have no more than this number of buttons in each column. Fires amaxButtonRows
property change event.- Parameters:
maxButtonRows
- Maximum button rows for this panel.- See Also:
-
getMaxButtonRows
public int getMaxButtonRows()Returns the maximum button rows for this panel. The return value is relevant only when the layout kind isJCommandButtonPanel.LayoutKind.COLUMN_FILL
.- Returns:
- Maximum button rows for this panel.
- See Also:
-
getGroupButtons
Returns the list of all buttons in the specified button group.- Parameters:
groupIndex
- Group index.- Returns:
- Unmodifiable view on the list of all buttons in the specified button group.
- See Also:
-
setSingleSelectionMode
public void setSingleSelectionMode(boolean isSingleSelectionMode) Sets the selection mode for this panel. Iftrue
is passed as the parameter, allJCommandToggleButton
in this panel are set to belong to the same button group.- Parameters:
isSingleSelectionMode
- Iftrue
,allJCommandToggleButton
in this panel are set to belong to the same button group.- See Also:
-
setToShowGroupLabels
public void setToShowGroupLabels(boolean toShowGroupLabels) Sets indication whether button group labels should be shown. Fires atoShowGroupLabels
property change event.- Parameters:
toShowGroupLabels
- Iftrue
, this panel will show the labels of the button groups.- See Also:
-
isToShowGroupLabels
public boolean isToShowGroupLabels()Returns indication whether button group labels should be shown.- Returns:
- If
true
, this panel shows the labels of the button groups, andfalse
otherwise. - See Also:
-
setIconDimension
public void setIconDimension(int dimension) Sets the new dimension for the icons in this panel. The state for all the icons is set toCommandButtonDisplayState.FIT_TO_ICON
.- Parameters:
dimension
- New dimension for the icons in this panel.- See Also:
-
setIconState
Sets the new state for the icons in this panel. The dimension for all the icons is set to -1; this method should only be called with a state that has an associated default size (likeCommandButtonDisplayState.BIG
,CommandButtonDisplayState.TILE
,CommandButtonDisplayState.MEDIUM
andCommandButtonDisplayState.SMALL
).- Parameters:
state
- New state for the icons in this panel.- See Also:
-
getSelectedButton
Returns the selected button of this panel. Only relevant for single selection mode (set bysetSingleSelectionMode(boolean)
), returningnull
otherwise.- Returns:
- The selected button of this panel.
- See Also:
-
getLayoutKind
Returns the layout kind of this panel.- Returns:
- Layout kind of this panel.
- See Also:
-
setLayoutKind
Sets the new layout kind for this panel. Fires alayoutKind
property change event.- Parameters:
layoutKind
- New layout kind for this panel.- See Also:
-
addChangeListener
Adds the specified change listener to this button panel.- Parameters:
l
- Change listener to add.- See Also:
-
removeChangeListener
Removes the specified change listener from this button panel.- Parameters:
l
- Change listener to remove.- See Also:
-
fireStateChanged
protected void fireStateChanged()Notifies all registered listener that the state of this command button panel has changed. -
getPreferredScrollableViewportSize
- Specified by:
getPreferredScrollableViewportSize
in interfaceScrollable
-
getScrollableBlockIncrement
- Specified by:
getScrollableBlockIncrement
in interfaceScrollable
-
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()- Specified by:
getScrollableTracksViewportHeight
in interfaceScrollable
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()- Specified by:
getScrollableTracksViewportWidth
in interfaceScrollable
-
getScrollableUnitIncrement
- Specified by:
getScrollableUnitIncrement
in interfaceScrollable
-