uic.widgets
Class ToolBarButton

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.AbstractButton
                  extended by javax.swing.JButton
                      extended by uic.widgets.ToolBarButton
All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants

public class ToolBarButton
extends JButton

Button that behaves like a normal JButton, but looks different. It has no border and has a rollover-icon by default.

This button can have a popupmenu assigned to it, and have a default "pressed" action at the same time allowing a normal button press to trigger the default action and when the user keeps the button depressed for a specified delay the popup menu will appear. An example of setting the popupmenu:

  ToolBarButton bt = new ToolBarButton();         // create new empty button
  JPopupMenu myJPopupMenu = new JPopupMenu();
  myJPopupMenu.add(new JMenuItem("First"));       // register menu items that should be shown
  myJPopupMenu.add(new JMenuItem("Second item")); //  on longer selection
  bt.setPopupMenu(myJPopupMenu);                  // register the menu with the toolbar button.
 
Setting of the default action (which is the action when the button is pressed without triggering the popup to show) you just have add an action listener to this button, like on all AbstractButton extending classes.
NOTE: registring an action listener will use the popupDelay or a default if none set.

Since:
2.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JButton
JButton.AccessibleJButton
 
Nested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
 
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.AbstractButton
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
 
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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ToolBarButton()
          Constructor.
ToolBarButton(Icon icon)
           
ToolBarButton(String label)
          Constructor.
ToolBarButton(String text, Icon icon)
           
ToolBarButton(String text, IconFactory iconFactory, String iconBaseName)
           
 
Method Summary
 void addActionListener(ActionListener listener)
          Override to set the initial delay of the popupmenu to be shown (if available).
 ActionListener createActionListener()
          Override to overcome double events fired.
protected  void fireActionPerformed(ActionEvent event)
           
 Dimension getMinimumSize()
           
 int getPopupDelay()
          Returns the popup menu delay.
 Dimension getPreferredSize()
           
 boolean getToggleButton()
          Returns returns if this button is a togglebutton.
 boolean hasPopupMenu()
           
 boolean isFocusTraversable()
           
 void paintComponent(Graphics g)
           
 void removeActionListener(ActionListener listener)
          Override to set the initial delay of the popupmenu to be shown (if available).
 void setBorder(Border b)
          Overriden method to overcome border settings.
 void setIcon(Icon icon)
          Set the icon.
 void setPopupDelay(int popupDelay)
          Set the popupmenu delay.
 void setPopupMenu(JPopupMenu menu)
          Set the popupmenu to show on click.
 void setSelected(boolean on)
          If this button is a togglebutton, set it to be selected currently.
 void setText(String text)
           
 void setToggleButton(boolean on)
          Set this button to behave like it is a toggleButton.
 
Methods inherited from class javax.swing.JButton
configurePropertiesFromAction, getAccessibleContext, getUIClassID, isDefaultButton, isDefaultCapable, paramString, removeNotify, setDefaultCapable, updateUI
 
Methods inherited from class javax.swing.AbstractButton
addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setUI, setVerticalAlignment, setVerticalTextPosition
 
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, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, 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, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, 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
 

Constructor Detail

ToolBarButton

public ToolBarButton()
Constructor.


ToolBarButton

public ToolBarButton(String label)
Constructor.

Parameters:
label - the label to show on the button

ToolBarButton

public ToolBarButton(Icon icon)

ToolBarButton

public ToolBarButton(String text,
                     Icon icon)

ToolBarButton

public ToolBarButton(String text,
                     IconFactory iconFactory,
                     String iconBaseName)
Method Detail

setText

public void setText(String text)
Overrides:
setText in class AbstractButton

setToggleButton

public void setToggleButton(boolean on)
Set this button to behave like it is a toggleButton. A toggle button is either selected or unselected toggeling between the two using a mouseclick.

Parameters:
on - true if this button should behave like a togglebutton.

getToggleButton

public boolean getToggleButton()
Returns returns if this button is a togglebutton.

Returns:
returns if this button is a togglebutton.

setSelected

public void setSelected(boolean on)
If this button is a togglebutton, set it to be selected currently.

Overrides:
setSelected in class AbstractButton
Parameters:
on - the selected state.

addActionListener

public void addActionListener(ActionListener listener)
Override to set the initial delay of the popupmenu to be shown (if available).

Overrides:
addActionListener in class AbstractButton
Parameters:
listener - the listener to be set

removeActionListener

public void removeActionListener(ActionListener listener)
Override to set the initial delay of the popupmenu to be shown (if available).

Overrides:
removeActionListener in class AbstractButton
Parameters:
listener - the listener to be set

createActionListener

public ActionListener createActionListener()
Override to overcome double events fired. Now returns null

Overrides:
createActionListener in class AbstractButton
Returns:
null

setBorder

public void setBorder(Border b)
Overriden method to overcome border settings. Overriden method to make sure this button does not have a border (as it is set by some themes) Borders are not allowed on toolbar buttons

Overrides:
setBorder in class JComponent
Parameters:
b - the border to be ignored :)

setIcon

public void setIcon(Icon icon)
Set the icon. Set the icon and make rollover enabled

Overrides:
setIcon in class AbstractButton
Parameters:
icon - the icon to set

setPopupDelay

public void setPopupDelay(int popupDelay)
Set the popupmenu delay. Set the popupmenu delay. The closer the value is to 0 the harder it is to fire the default action

Parameters:
popupDelay - the delay in millis to show the popupmenu
Throws:
IllegalArgumentException - when popupDelay < 0

getPopupDelay

public int getPopupDelay()
Returns the popup menu delay. Returns the popup menu delay and if not set by the user by means of setPopupDelay it returns 500

Returns:
the popupmenu delay in millis

isFocusTraversable

public boolean isFocusTraversable()
Overrides:
isFocusTraversable in class Component

setPopupMenu

public void setPopupMenu(JPopupMenu menu)
Set the popupmenu to show on click.

Parameters:
menu - the popup menu to show

hasPopupMenu

public boolean hasPopupMenu()

paintComponent

public void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

fireActionPerformed

protected void fireActionPerformed(ActionEvent event)
Overrides:
fireActionPerformed in class AbstractButton

getMinimumSize

public Dimension getMinimumSize()
Overrides:
getMinimumSize in class JComponent

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent


Copyright © 2002-2004 Thomas Zander Available under the Free Apache licence