JIDE 3.5.15

com.jidesoft.dialog
Class ButtonPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jidesoft.dialog.ButtonPanel
All Implemented Interfaces:
ButtonListener, ButtonNames, ImageObserver, MenuContainer, Serializable, EventListener, Accessible
Direct Known Subclasses:
ScrollableButtonPanel

public class ButtonPanel
extends JPanel
implements ButtonListener, ButtonNames

ButtonPanel can help to layout buttons easily in any dialogs.

For more detail, please refer to JIDE Dialogs Developer Guide.

See Also:
Serialized Form

Nested Class Summary
 
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
static String AFFIRMATIVE_BUTTON
          The button will produce an affirmative action.
static String CANCEL_BUTTON
          The button will produce a cancel action.
static String HELP_BUTTON
          The button will open some help windows.
static String KEEP_PREFERRED_WIDTH
          Client property key.
static int NO_LESS_THAN
          This option will make all buttons no less than a certain size.
static String OTHER_BUTTON
          The button will produce an alternative action different neither an affirmative or cancel action.
static int SAME_SIZE
          This option will make all buttons have the same size.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.jidesoft.dialog.ButtonNames
APPLY, BACK, BROWSE, CANCEL, CLEAR, CLOSE, DETAILS, EDIT, EXIT, FIND, FIND_NEXT, FINISH, FORWARD, HELP, NEW, NEXT, NO, OK, OPEN, PRINT, REPLACE, RESET, RETRY, RUN, SAVE, SAVE_AS, STOP, YES
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ButtonPanel()
          Constructs a new ButtonPanel with right alignment.
ButtonPanel(int alignment)
          Constructs a new ButtonPanel with the specified alignment.
ButtonPanel(int alignment, int sizeConstrains)
          Constructs a new ButtonPanel with default horizontal spacing and the given alignment.
 
Method Summary
 void addButton(AbstractButton button)
          Adds button to ButtonPanel as AFFIRMATIVE_BUTTON.
 void addButton(AbstractButton button, int index)
          Adds button to ButtonPanel with specified type.
 void addButton(AbstractButton button, Object constraint)
          Adds button to ButtonPanel with specified constraint.
 void addButton(AbstractButton button, Object constraint, int index)
          Adds button to ButtonPanel with specified type.
protected  void addImpl(Component comp, Object constraints, int index)
           
 void addNotify()
           
 void buttonEventFired(ButtonEvent e)
          Invoked when the target of the listener request button to change state.
 int getAlignment()
          Gets the alignment of the ButtonPanel.
 Component getButtonByName(String name)
          Gets the button with the name.
 int getButtonGap()
          Gets the gap between two buttons in the same group.
 String getButtonOrder()
          Gets the button order.
 int getGroupGap()
          Gets the gap between two button groups.
 int getMinButtonWidth()
          Gets the minimum button width.
 String getOppositeButtonOrder()
          Gets the opposite button order.
 int getSizeConstraint()
          Gets the size constraint.
protected  void reinstallDefaults()
           
 void removeButton(AbstractButton button)
          Removes the button.
 void setAlignment(int alignment)
          Sets the alignment.
 void setButtonGap(int buttonGap)
          Sets the gap between two buttons in the same group.
 void setButtonOrder(String buttonOrder)
          Sets the button order.
 void setGroupGap(int groupGap)
          Sets the gap between two button groups.
 void setMinButtonWidth(int minButtonWidth)
          Sets the minimum button width.
 void setOppositeButtonOrder(String oppositeButtonOrder)
          Sets the opposite button order.
 void setSizeConstraint(int sizeConstrains)
          Sets the size constraint.
 void updateUI()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, 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, transferFocusBackward, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SAME_SIZE

public static final int SAME_SIZE
This option will make all buttons have the same size. If all buttons have the same size, the GUI will certainly look better.

See Also:
Constant Field Values

NO_LESS_THAN

public static final int NO_LESS_THAN
This option will make all buttons no less than a certain size. The size is different on different platforms. We need this option because sometimes one button has a very long text. If all buttons have the same size, it will make the button panel extremely long. Even though they have the same size but will look out of balance. This option is not available if the buttons are arranged vertically.

See Also:
Constant Field Values

KEEP_PREFERRED_WIDTH

public static final String KEEP_PREFERRED_WIDTH
Client property key. If this client property is set to Boolean.TRUE, the button panel will always use the component's preferred width instead of using minButtonWidth.

See Also:
Constant Field Values

AFFIRMATIVE_BUTTON

public static final String AFFIRMATIVE_BUTTON
The button will produce an affirmative action. Typical affirmative buttons are OK, Save, Print, Replace etc. It doesn't have to be positive either. For example, both Yes and No are affirmative action. This constant is used as constraint parameter in addButton(javax.swing.AbstractButton, Object) method.

See Also:
Constant Field Values

CANCEL_BUTTON

public static final String CANCEL_BUTTON
The button will produce a cancel action. Typical cancel button is Cancel. This constant is used as constraint parameter in addButton(javax.swing.AbstractButton, Object) method.

See Also:
Constant Field Values

HELP_BUTTON

public static final String HELP_BUTTON
The button will open some help windows. This constant is used as constraint parameter in addButton(javax.swing.AbstractButton, Object) method.

See Also:
Constant Field Values

OTHER_BUTTON

public static final String OTHER_BUTTON
The button will produce an alternative action different neither an affirmative or cancel action. Typical alternative button is Don't Save comparing with Save as affirmative action and Cancel as cancel action. This constant is used as constraint parameter in addButton(javax.swing.AbstractButton, Object) method.

See Also:
Constant Field Values
Constructor Detail

ButtonPanel

public ButtonPanel()
Constructs a new ButtonPanel with right alignment.


ButtonPanel

public ButtonPanel(int alignment)
Constructs a new ButtonPanel with the specified alignment.

Parameters:
alignment - the alignment. The supported alignment are SwingConstants.RIGHT, SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.TOP or SwingConstants.BOTTOM.

ButtonPanel

public ButtonPanel(int alignment,
                   int sizeConstrains)
Constructs a new ButtonPanel with default horizontal spacing and the given alignment.

Parameters:
alignment - the alignment of the buttons. It can be one of SwingConstants.LEFT or SwingConstants.RIGHT or SwingConstants.TOP or SwingConstants.BOTTOM or SwingConstants.CENTER.
sizeConstrains - size constraint of the button. It can be either SAME_SIZE or NO_LESS_THAN
Method Detail

updateUI

public void updateUI()
Overrides:
updateUI in class JPanel

reinstallDefaults

protected void reinstallDefaults()

setAlignment

public void setAlignment(int alignment)
Sets the alignment. If the alignment is one of SwingConstants.CENTER, SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING, the buttons will be laid out horizontally. If the alignment is SwingConstants.TOP or SwingConstants.BOTTOM, the buttons will be laid out vertically.

Parameters:
alignment - the alignment. The supported alignment are SwingConstants.RIGHT, SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.TOP or SwingConstants.BOTTOM.

getAlignment

public int getAlignment()
Gets the alignment of the ButtonPanel.

Returns:
the alignment of the ButtonPanel.

addButton

public void addButton(AbstractButton button)
Adds button to ButtonPanel as AFFIRMATIVE_BUTTON.

Parameters:
button - a button

addButton

public void addButton(AbstractButton button,
                      int index)
Adds button to ButtonPanel with specified type.

Parameters:
button - a button.
index - the position in the button panel's list at which to insert the component; -1 means insert at the end component

addButton

public void addButton(AbstractButton button,
                      Object constraint)
Adds button to ButtonPanel with specified constraint. The valid constraints are AFFIRMATIVE_BUTTON, CANCEL_BUTTON,OTHER_BUTTON and HELP_BUTTON. The main purpose of the constraints is to determine how the buttons are laid out on different platforms according to the OS convention. For example, on Windows, AFFIRMATIVE_BUTTON appears on the right hand side of CANCEL_BUTTON. On Mac OS X, AFFIRMATIVE_BUTTON will appear on the left hand side of CANCEL_BUTTON.

Parameters:
button - a button.
constraint - one of constraints.

addButton

public void addButton(AbstractButton button,
                      Object constraint,
                      int index)
Adds button to ButtonPanel with specified type.

Parameters:
button - a button.
constraint - String of one of types.
index - the position in the button panel's list at which to insert the component; -1 means insert at the end component

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
Overrides:
addImpl in class Container

removeButton

public void removeButton(AbstractButton button)
Removes the button. It's the same as Container.remove(java.awt.Component).

Parameters:
button - a button

getButtonOrder

public String getButtonOrder()
Gets the button order.

Returns:
the button order.

setButtonOrder

public void setButtonOrder(String buttonOrder)
Sets the button order.

Parameters:
buttonOrder - the new button order.

getOppositeButtonOrder

public String getOppositeButtonOrder()
Gets the opposite button order.

Returns:
the opposite button order.

setOppositeButtonOrder

public void setOppositeButtonOrder(String oppositeButtonOrder)
Sets the opposite button order.

Parameters:
oppositeButtonOrder - the new opposite button order.

getSizeConstraint

public int getSizeConstraint()
Gets the size constraint.

Returns:
the size constraint.

setSizeConstraint

public void setSizeConstraint(int sizeConstrains)
Sets the size constraint. Valid values are NO_LESS_THAN and SAME_SIZE. The size constraint will apply to all components except if the component client property KEEP_PREFERRED_WIDTH is set to Boolean.TRUE.

Parameters:
sizeConstrains - the size constraint.

getGroupGap

public int getGroupGap()
Gets the gap between two button groups.

Returns:
the gap between two button groups.

setGroupGap

public void setGroupGap(int groupGap)
Sets the gap between two button groups.

Parameters:
groupGap - the gap between button groups.

getButtonGap

public int getButtonGap()
Gets the gap between two buttons in the same group.

Returns:
the gap between two buttons in the same group.

setButtonGap

public void setButtonGap(int buttonGap)
Sets the gap between two buttons in the same group.

Parameters:
buttonGap - the gap between buttons.

getMinButtonWidth

public int getMinButtonWidth()
Gets the minimum button width.

Returns:
the minimum button width.

setMinButtonWidth

public void setMinButtonWidth(int minButtonWidth)
Sets the minimum button width.

Parameters:
minButtonWidth - the minimum button width.

buttonEventFired

public void buttonEventFired(ButtonEvent e)
Description copied from interface: ButtonListener
Invoked when the target of the listener request button to change state.

Specified by:
buttonEventFired in interface ButtonListener
Parameters:
e - a ButtonEvent object

addNotify

public void addNotify()
Overrides:
addNotify in class JComponent

getButtonByName

public Component getButtonByName(String name)
Gets the button with the name. In order to use this method, you have to set a name to the button using Component.setName(String) method. Please note, the name is not the same as the constraint in the second parameter of Container.add(java.awt.Component, Object).

Parameters:
name - the button name.
Returns:
the button which has the name. null if there is no button with that name.
Throws:
IllegalArgumentException - if the name is null or empty.

JIDE 3.5.15