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 enumEnumerates the available layout kinds.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 TypeFieldDescriptionprotected CommandToggleButtonGroupThe button group for the single selection mode.protected List<List<AbstractCommandButton>>List of all button groups.protected intCurrent icon dimension.protected CommandButtonDisplayStateCurrent icon state.List of titles for all button groups.protected booleanIndicates the selection mode for theJCommandToggleButtonin this panel.protected JCommandButtonPanel.LayoutKindLayout kind of this button panel.protected intMaximum number of columns for this panel.protected intMaximum number of rows for this panel.protected booleanIftrue, the panel will show group labels.static final StringFields 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
ConstructorsModifierConstructorDescriptionprotectedCreates a new panel.JCommandButtonPanel(int startingDimension) Creates a new panel.JCommandButtonPanel(CommandButtonDisplayState startingState) Creates a new panel. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddButtonGroup(String buttonGroupName) Adds a new button group after all the existing button groups.voidaddButtonGroup(String buttonGroupName, int groupIndex) Adds a new button group at the specified index.intaddButtonToGroup(String buttonGroupName, int indexInGroup, AbstractCommandButton commandButton) Adds a new button to the specified button group.intaddButtonToGroup(String buttonGroupName, AbstractCommandButton commandButton) Adds a new button to the specified button group.intaddButtonToLastGroup(AbstractCommandButton commandButton) Adds a new button to the specified button group.voidAdds the specified change listener to this button panel.protected voidNotifies all registered listener that the state of this command button panel has changed.intReturns the number of buttons in this panel.getGroupButtons(int groupIndex) Returns the list of all buttons in the specified button group.intReturns 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.intReturns the maximum button columns for this panel.intReturns the maximum button rows for this panel.intgetScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) booleanbooleanintgetScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) Returns the selected button of this panel.booleanReturns indication whether button group labels should be shown.voidRemoves all the button groups and buttons from this panel.voidremoveButtonFromGroup(String buttonGroupName, int indexInGroup) Removes the button at the specified index from the specified button group.voidremoveButtonGroup(String buttonGroupName) Removes the specified button group.voidRemoves the specified change listener from this button panel.voidsetIconDimension(int dimension) Sets the new dimension for the icons in this panel.voidSets the new state for the icons in this panel.voidsetLayoutKind(JCommandButtonPanel.LayoutKind layoutKind) Sets the new layout kind for this panel.voidsetMaxButtonColumns(int maxButtonColumns) Sets the maximum button columns for this panel.voidsetMaxButtonRows(int maxButtonRows) Sets the maximum button rows for this panel.voidsetSingleSelectionMode(boolean isSingleSelectionMode) Sets the selection mode for this panel.voidsetToShowGroupLabels(boolean toShowGroupLabels) Sets indication whether button group labels should be shown.voidupdateUI()Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, paramString, setUIMethods 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, 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, 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. -
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 theJCommandToggleButtonin this panel.- See Also:
-
toShowGroupLabels
protected boolean toShowGroupLabelsIftrue, the panel will show group labels. -
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. -
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:
getUIClassIDin 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 amaxButtonColumnsproperty 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 amaxButtonRowsproperty 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. Iftrueis passed as the parameter, allJCommandToggleButtonin this panel are set to belong to the same button group.- Parameters:
isSingleSelectionMode- Iftrue,allJCommandToggleButtonin 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 atoShowGroupLabelsproperty 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, andfalseotherwise. - 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.MEDIUMandCommandButtonDisplayState.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)), returningnullotherwise.- 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 alayoutKindproperty 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:
getPreferredScrollableViewportSizein interfaceScrollable
-
getScrollableBlockIncrement
- Specified by:
getScrollableBlockIncrementin interfaceScrollable
-
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()- Specified by:
getScrollableTracksViewportHeightin interfaceScrollable
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()- Specified by:
getScrollableTracksViewportWidthin interfaceScrollable
-
getScrollableUnitIncrement
- Specified by:
getScrollableUnitIncrementin interfaceScrollable
-