public class Button
extends javax.swing.AbstractButton
implements java.awt.event.ActionListener, java.lang.Cloneable, java.beans.PropertyChangeListener
A Button object is a button that can take different configuration. It can be sticky or not, it can popup a menu defined by an array of ButtonDef, etc.
If a group is specified :
Initially, all buttons in the group are unselected. Once any button is selected, one button is always selected in
the group. There is no way to turn a button programmatically to "off", in order to clear the button group.
Examples of configurations
Button(new ButtonDef("theAction", anIcon, null, true), false, new Dimension(32, 32));
Button(new ButtonDef("theAction", anIcon, "Example", true), true, new Dimension(32, 32));
Button(new ButtonDef("theAction", anIcon, "Example", true), aButtonGroup, new Dimension(32, 32));
ButtonDef bDefA = new ButtonDef("actionA", anIcon, "Choice A", false);
ButtonDef bDefB = new ButtonDef("actionB", anIcon, "Choice B", false);
ButtonDef bDefC = new ButtonDef("actionC", anIcon, "Choice C", false);
Button(anIcon, "List of actions", false, new ButtonDef[]{bDefA, bDefB, bDefC}, null);
ButtonDef bDefA = new ButtonDef("actionA", anIcon, "Choice A", false);
ButtonDef bDefB = new ButtonDef("actionB", anIcon, "Choice B", false);
ButtonDef bDefC = new ButtonDef("actionC", anIcon, "Choice C", false);
Button(new ButtonDef[]{bDefA, bDefB, bDefC}, 0, 1, new Dimension(44, 32));
ButtonDef bDefA = new ButtonDef("actionA", anIcon, "Choice A", false);
ButtonDef bDefB = new ButtonDef("actionB", anIcon, "Choice B", false);
ButtonDef bDefC = new ButtonDef("actionC", anIcon, "Choice C", false);
Button(new ButtonDef[]{bDefA, bDefB, bDefC}, 0, false, new Dimension(44, 32));
ButtonDef bDefA = new ButtonDef("actionA", anIcon, "Choice A", false);
ButtonDef bDefB = new ButtonDef("actionB", anIcon, "Choice B", false);
ButtonDef bDefC = new ButtonDef("actionC", anIcon, "Choice C", false);
Button(new ButtonDef[]{bDefA, bDefB, bDefC}, 2, true, aButtonGroup, new Dimension(44, 32));
ButtonDef
,
ButtonGroup
,
Serialized Formjavax.swing.AbstractButton.AccessibleAbstractButton, javax.swing.AbstractButton.ButtonChangeListener
javax.swing.JComponent.AccessibleJComponent
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
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 |
---|
Button()
Default constructor.
|
Button(javax.swing.Action action,
boolean sticky,
java.awt.Dimension dimension) |
Button(javax.swing.Action action,
ButtonGroup buttonGroup,
java.awt.Dimension dimension) |
Button(ButtonDef[] buttonDefs,
int defaultActionIdx,
boolean sticky,
ButtonGroup buttonGroup,
java.awt.Dimension dimension)
Constructs a button that will be updated with the choice made in the popup menu.
|
Button(ButtonDef[] buttonDefs,
int defaultActionIdx,
boolean sticky,
java.awt.Dimension dimension)
Constructs a button that will be updated with the choice made in the popup menu.
|
Button(ButtonDef[] buttonDefs,
int defaultActionIdx,
int popupDefaultActionIdx,
java.awt.Dimension dimension)
Constructs a button that displays a popup menu when the user clicks on the little pop bar.
|
Button(ButtonDef buttonDef,
boolean sticky,
java.awt.Dimension dimension)
Construct a normal button.
|
Button(ButtonDef buttonDef,
ButtonGroup buttonGroup,
java.awt.Dimension dimension)
Constructs a normal sticky button with a button group.
|
Button(javax.swing.ImageIcon icon,
java.lang.String text,
boolean centerIconText,
ButtonDef[] buttonDefs,
boolean updateButtonWithUserChoice,
java.awt.Dimension dimension)
Constructs a button that will pop a popup menu when the user click on it.
|
Button(javax.swing.ImageIcon icon,
java.lang.String text,
boolean centerIconText,
ButtonDef[] buttonDefs,
java.awt.Dimension dimension)
Deprecated.
use Button(ImageIcon, String, boolean, ButtonDef[], false, Dimension)
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent ae) |
java.lang.Object |
clone()
Clones the Button
|
java.lang.String |
getCurrentActionName()
Returns the current action name of the button
|
java.lang.String |
getText()
Returns the current visible text.
|
boolean |
isSelected()
Returs the selected state of this button.
|
void |
paintComponent(java.awt.Graphics g) |
protected void |
processMouseEvent(java.awt.event.MouseEvent mouseevent) |
void |
propertyChange(java.beans.PropertyChangeEvent pce) |
void |
setCurrentAction(java.lang.String actionName) |
void |
setFixedHeight(int height)
Sets the height of the button.
|
void |
setFixedSize(java.awt.Dimension dimension)
Sets the size of the button.
|
void |
setFixedWidth(int width)
Sets the width of the button.
|
void |
setIcon(javax.swing.Icon icon)
Sets the icon of the current button definition.
|
void |
setIcon(java.awt.Image imgTexture,
int w,
int h)
Sets the icon of the current button definition.
|
void |
setIcon(int colorRGB,
int w,
int h)
Creates and sets an icon of a specific RGB color.
|
void |
setSelected(boolean isSelected)
Sets the selected state of the button.
|
void |
setSize(java.awt.Dimension dim) |
void |
setSize(int width,
int height) |
void |
setSticky(boolean sticky) |
void |
setText(int buttonDefIdx,
java.lang.String newText)
Change the text for a button definition.
|
void |
setText(java.lang.String newText)
Change the current visible text of the button.
|
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, paintBorder, paramString, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, 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, getAccessibleContext, 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, 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, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public Button()
public Button(ButtonDef buttonDef, boolean sticky, java.awt.Dimension dimension)
buttonDef
- the definition of this buttonsticky
- the sticky statedimension
- the dimension of the button. If null
, the dimension will be calculated depending
on the icon and/or the textpublic Button(javax.swing.Action action, boolean sticky, java.awt.Dimension dimension)
public Button(ButtonDef buttonDef, ButtonGroup buttonGroup, java.awt.Dimension dimension)
buttonDef
- the definition of this buttonbuttonGroup
- a button group. The button group can't be null
.dimension
- the dimension of the button. If null
, the dimension will be calculated depending
on the icon and/ord the textpublic Button(javax.swing.Action action, ButtonGroup buttonGroup, java.awt.Dimension dimension)
@Deprecated public Button(javax.swing.ImageIcon icon, java.lang.String text, boolean centerIconText, ButtonDef[] buttonDefs, java.awt.Dimension dimension)
icon
- the icon to be displayed. Can be null
text
- the text to be displayed. Can be null
centerIconText
- center state of the icon/textbuttonDefs
- an array of button definitionsdimension
- the dimension of the button. If null
, the dimension will be calculated depending
on the icon and/ord the textpublic Button(javax.swing.ImageIcon icon, java.lang.String text, boolean centerIconText, ButtonDef[] buttonDefs, boolean updateButtonWithUserChoice, java.awt.Dimension dimension)
icon
- the icon to be displayed. Can be null
text
- the text to be displayed. Can be null
centerIconText
- center state of the icon/textbuttonDefs
- an array of button definitionsupdateButtonWithUserChoice
- if true, the button will be updated with the user's choicedimension
- the dimension of the button. If null
, the dimension will be calculated depending
on the icon and/ord the textpublic Button(ButtonDef[] buttonDefs, int defaultActionIdx, int popupDefaultActionIdx, java.awt.Dimension dimension)
popupDefaultActionIdx
will be fired. This button will not be sticky.buttonDefs
- an array of button definitionsdefaultActionIdx
- the default button definition displayedpopupDefaultActionIdx
- the action name to be fired when the user clicks directly on the buttondimension
- the dimension of the button. If null
, the dimension will be calculated depending
on the icon and/or the textpublic Button(ButtonDef[] buttonDefs, int defaultActionIdx, boolean sticky, java.awt.Dimension dimension)
buttonDefs
- an array of button definitionsdefaultActionIdx
- the default button definition displayedsticky
- sticky optiondimension
- the dimension of the button. If null
, the dimension will be calculated depending
on the icon and/or the textpublic Button(ButtonDef[] buttonDefs, int defaultActionIdx, boolean sticky, ButtonGroup buttonGroup, java.awt.Dimension dimension)
null
, sticky
option will be set to true
.buttonDefs
- an array of button definitionsdefaultActionIdx
- the default button definition displayedsticky
- sticky option. (Overriden if the buttonGroup is not null
)buttonGroup
- a button group. If not null
, the sticky option is sets to true
dimension
- the dimension of the button. If null
, the dimension will be calculated depending
on the icon and/or the textpublic void setFixedHeight(int height)
public void setFixedWidth(int width)
public void setFixedSize(java.awt.Dimension dimension)
null
size has no effectsdimension
- new sizepublic void setIcon(int colorRGB, int w, int h)
public void setIcon(java.awt.Image imgTexture, int w, int h)
imgTexture
- the iconw
- the widthh
- the heightpublic void setIcon(javax.swing.Icon icon)
setIcon
in class javax.swing.AbstractButton
icon
- the new iconpublic void setText(int buttonDefIdx, java.lang.String newText)
buttonDefIdx
- the idx to changenewText
- the new textpublic void setText(java.lang.String newText)
null
value
remove the current text.setText
in class javax.swing.AbstractButton
newText
- the text to display.public java.lang.String getText()
getText
in class javax.swing.AbstractButton
null
if there is no textpublic boolean isSelected()
isSelected
in class javax.swing.AbstractButton
public void setSelected(boolean isSelected)
setSelected
in class javax.swing.AbstractButton
isSelected
- selected statepublic java.lang.String getCurrentActionName()
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
protected void processMouseEvent(java.awt.event.MouseEvent mouseevent)
processMouseEvent
in class javax.swing.JComponent
public void actionPerformed(java.awt.event.ActionEvent ae)
actionPerformed
in interface java.awt.event.ActionListener
public void setCurrentAction(java.lang.String actionName)
public java.lang.Object clone()
clone
in class java.lang.Object
public void propertyChange(java.beans.PropertyChangeEvent pce)
propertyChange
in interface java.beans.PropertyChangeListener
public void setSize(java.awt.Dimension dim)
setSize
in class java.awt.Component
public void setSize(int width, int height)
setSize
in class java.awt.Component
public void setSticky(boolean sticky)