public class ButtonPanel extends javax.swing.JPanel implements ButtonListener, ButtonNames
ButtonPanel
can help to layout buttons easily in any dialogs.
For more detail, please refer to JIDE Dialogs Developer Guide.javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AFFIRMATIVE_BUTTON
The button will produce an affirmative action.
|
static java.lang.String |
CANCEL_BUTTON
The button will produce a cancel action.
|
static java.lang.String |
HELP_BUTTON
The button will open some help windows.
|
static java.lang.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 java.lang.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.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
ButtonPanel()
Constructs a new
ButtonPanel with right alignment. |
ButtonPanel(int alignment)
Constructs a new
ButtonPanel with the specified alignment. |
ButtonPanel(int alignment,
int sizeContraint)
Constructs a new
ButtonPanel with default horizontal spacing and the given alignment. |
Modifier and Type | Method and Description |
---|---|
void |
addButton(javax.swing.AbstractButton button)
Adds button to ButonPanel as AFFIRMATIVE_BUTTON.
|
void |
addButton(javax.swing.AbstractButton button,
int index)
Adds button to ButonPanel with specified type.
|
void |
addButton(javax.swing.AbstractButton button,
java.lang.Object constraint)
Adds button to ButonPanel with specified constraint.
|
void |
addButton(javax.swing.AbstractButton button,
java.lang.Object constraint,
int index)
Adds button to ButonPanel with specified type.
|
protected void |
addImpl(java.awt.Component comp,
java.lang.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.
|
java.awt.Component |
getButtonByName(java.lang.String name)
Gets the button with the name.
|
int |
getButtonGap()
Gets the gap between two buttons in the same group.
|
java.lang.String |
getButtonOrder()
Gets the button order.
|
int |
getGroupGap()
Gets the gap between two button groups.
|
int |
getMinButtonWidth()
Gets the minimum button width.
|
java.lang.String |
getOppositeButtonOrder()
Gets the opposite button order.
|
int |
getSizeConstraint()
Gets the size constraint.
|
protected void |
reinstallDefaults() |
void |
removeButton(javax.swing.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(java.lang.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(java.lang.String oppositeButtonOrder)
Sets the opposite button order.
|
void |
setSizeConstraint(int sizeContraint)
Sets the size constraint.
|
void |
updateUI() |
getAccessibleContext, getUI, getUIClassID, paramString, setUI
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, 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
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, transferFocusDownCycle, validate, validateTree
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, 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, transferFocusBackward, transferFocusUpCycle
public static final int SAME_SIZE
public static final int NO_LESS_THAN
public static final java.lang.String KEEP_PREFERRED_WIDTH
public static final java.lang.String AFFIRMATIVE_BUTTON
addButton(javax.swing.AbstractButton,Object)
method.public static final java.lang.String CANCEL_BUTTON
addButton(javax.swing.AbstractButton,Object)
method.public static final java.lang.String HELP_BUTTON
addButton(javax.swing.AbstractButton,Object)
method.public static final java.lang.String OTHER_BUTTON
addButton(javax.swing.AbstractButton,Object)
method.public ButtonPanel()
ButtonPanel
with right alignment.public ButtonPanel(int alignment)
ButtonPanel
with the specified alignment.alignment
- the alignment. The supported alignment are SwingConstants.RIGHT
, SwingConstants.LEFT
, SwingConstants.CENTER
, SwingConstants.TOP
or SwingConstants.BOTTOM
.public ButtonPanel(int alignment, int sizeContraint)
ButtonPanel
with default horizontal spacing and the given alignment.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
.sizeContraint
- size constraint of the button. It can be either SAME_SIZE
or
NO_LESS_THAN
public void updateUI()
updateUI
in class javax.swing.JPanel
protected void reinstallDefaults()
public void setAlignment(int alignment)
alignment
- the alignment. The supported alignment are SwingConstants.RIGHT
, SwingConstants.LEFT
, SwingConstants.CENTER
, SwingConstants.TOP
or SwingConstants.BOTTOM
.public int getAlignment()
public void addButton(javax.swing.AbstractButton button)
button
- a buttonpublic void addButton(javax.swing.AbstractButton button, int index)
button
- a button.index
- the position in the button panel's list at which to insert the component; -1 means insert at the
end componentpublic void addButton(javax.swing.AbstractButton button, java.lang.Object constraint)
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.button
- a button.constraint
- one of constraints.public void addButton(javax.swing.AbstractButton button, java.lang.Object constraint, int index)
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 componentprotected void addImpl(java.awt.Component comp, java.lang.Object constraints, int index)
addImpl
in class java.awt.Container
public void removeButton(javax.swing.AbstractButton button)
Container.remove(java.awt.Component)
.button
- a buttonpublic java.lang.String getButtonOrder()
public void setButtonOrder(java.lang.String buttonOrder)
buttonOrder
- the new button order.public java.lang.String getOppositeButtonOrder()
public void setOppositeButtonOrder(java.lang.String oppositeButtonOrder)
oppositeButtonOrder
- the new opposite button order.public int getSizeConstraint()
public void setSizeConstraint(int sizeContraint)
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.sizeContraint
- the size constraint.public int getGroupGap()
public void setGroupGap(int groupGap)
groupGap
- the gap between button groups.public int getButtonGap()
public void setButtonGap(int buttonGap)
buttonGap
- the gap between buttons.public int getMinButtonWidth()
public void setMinButtonWidth(int minButtonWidth)
minButtonWidth
- the minimum button width.public void buttonEventFired(ButtonEvent e)
ButtonListener
buttonEventFired
in interface ButtonListener
e
- a ButtonEvent objectpublic void addNotify()
addNotify
in class javax.swing.JComponent
public java.awt.Component getButtonByName(java.lang.String name)
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)
.name
- the button name.java.lang.IllegalArgumentException
- if the name is null or empty.