com.jgoodies.uifextras.util
Class ActionLabel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by com.jgoodies.uif.component.UIFLabel
                      extended by com.jgoodies.uifextras.util.ActionLabel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public final class ActionLabel
extends com.jgoodies.uif.component.UIFLabel

A UIFLabel subclass that paints a hyperlink-like underline on mouseover. Mouse clicks can perform an action either by setting this label's Action or by adding an ActionListener to this label.

If the mouse enters this label the hand cursor is set; this cursor will be removed either if the mouse exited or if the action performed makes the label not showing.

TODO: Consider adding support for mnemonics.

Version:
$Revision: 1.10 $
Author:
Karsten Lentzsch
See Also:
Action, ActionListener, Component.isShowing(), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
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
 
Fields inherited from class com.jgoodies.uif.component.UIFLabel
PROPERTYNAME_ANTI_ALIASED, PROPERTYNAME_FONT_SIZE_DELTA, PROPERTYNAME_FONT_STYLE
 
Fields inherited from class javax.swing.JLabel
labelFor
 
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
ActionLabel(Action action)
          Creates an ActionLabel where properties are taken from the Action supplied.
ActionLabel(String text)
          Creates an ActionLabel with the given text.
ActionLabel(String text, Color linkColor, Color backgroundColor)
          Creates an ActionLabel with the given text, and colors for the link and label background.
ActionLabel(String text, Color linkColor, Color backgroundColor, Icon icon, int horizontalAlignment)
          Creates an ActionLabel with the given text, link color, background color, icon, and horizontal alignment.
ActionLabel(String text, Icon icon, int horizontalAlignment)
          Creates an ActionLabel with the given text, icon, and horizontal alignment.
 
Method Summary
 void addActionListener(ActionListener listener)
          Adds an action listener to receive action events from this label.
 Action getAction()
          Returns the currently set Action for this ActionEvent source, or null if no Action is set.
 Color getBackgroundColor()
          Returns the background color for the activated label.
 Icon getDisabledIcon()
          Returns the icon used by this label when it's disabled.
 Color getLinkColor()
          Returns the color for the activated label.
 void paint(Graphics g)
          Paints the label.
 void removeActionListener(ActionListener listener)
          Removes the given action listener from the list of action listeners associated with this label.
 void setAction(Action a)
          Sets the Action for the ActionEvent source.
 void setBackgroundColor(Color color)
          Sets the background color for the activated label.
 void setLinkColor(Color color)
          Sets the color for the activated label.
 
Methods inherited from class com.jgoodies.uif.component.UIFLabel
getFontSizeDelta, getFontStyle, isAntiAliased, setAntiAliased, setFontSizeDelta, setFontStyle, updateUI
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, 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, 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, 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, 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, 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, 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
 

Constructor Detail

ActionLabel

public ActionLabel(String text)
Creates an ActionLabel with the given text.

Parameters:
text - the text to be displayed

ActionLabel

public ActionLabel(String text,
                   Icon icon,
                   int horizontalAlignment)
Creates an ActionLabel with the given text, icon, and horizontal alignment.

Parameters:
text - the text to be displayed
icon - the icon to be displayed
horizontalAlignment - one of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING

ActionLabel

public ActionLabel(String text,
                   Color linkColor,
                   Color backgroundColor)
Creates an ActionLabel with the given text, and colors for the link and label background.

Parameters:
text - the text to be displayed
linkColor - the color of the activated label
backgroundColor - the background color of the activated label

ActionLabel

public ActionLabel(String text,
                   Color linkColor,
                   Color backgroundColor,
                   Icon icon,
                   int horizontalAlignment)
Creates an ActionLabel with the given text, link color, background color, icon, and horizontal alignment.

Parameters:
text - the text to be displayed
linkColor - the color of the activated label
backgroundColor - the background color of activated label
icon - the icon to be displayed
horizontalAlignment - one of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING

ActionLabel

public ActionLabel(Action action)
Creates an ActionLabel where properties are taken from the Action supplied.

Parameters:
action - the Action used to specify the new ActionLabel
Method Detail

getLinkColor

public Color getLinkColor()
Returns the color for the activated label.

Returns:
color of activated label

setLinkColor

public void setLinkColor(Color color)
Sets the color for the activated label.

Parameters:
color - color of activated label

getBackgroundColor

public Color getBackgroundColor()
Returns the background color for the activated label.

Returns:
background color of activated label

setBackgroundColor

public void setBackgroundColor(Color color)
Sets the background color for the activated label.

Parameters:
color - background color of activated label

getAction

public Action getAction()
Returns the currently set Action for this ActionEvent source, or null if no Action is set.

Returns:
the Action for this ActionEvent source, or null
See Also:
Action, setAction(Action)

setAction

public void setAction(Action a)
Sets the Action for the ActionEvent source. The new Action replaces any previously set Action but does not affect ActionListeners independently added with addActionListener. If the Action is already a registered ActionListener for the button, it is not re-registered.

A side-effect of setting the Action is that the ActionEvent source's properties are immediately set from the values in the Action (performed by the method configurePropertiesFromAction) and subsequently updated as the Action's properties change (via a PropertyChangeListener created by the method createActionPropertyChangeListener.

Parameters:
a - the Action for the AbstractButton, or null
See Also:
Action, getAction()

addActionListener

public void addActionListener(ActionListener listener)
Adds an action listener to receive action events from this label.

Parameters:
listener - ActionListener to add to the event queue

removeActionListener

public void removeActionListener(ActionListener listener)
Removes the given action listener from the list of action listeners associated with this label.

Parameters:
listener - ActionListener to add to the event queue

getDisabledIcon

public Icon getDisabledIcon()
Returns the icon used by this label when it's disabled. If no disabled icon has been set, the label tries to construct one from the default icon.

Overrides:
getDisabledIcon in class JLabel
Returns:
the disabledIcon property
See Also:
JLabel.setDisabledIcon(javax.swing.Icon)

paint

public void paint(Graphics g)
Paints the label.

Overrides:
paint in class com.jgoodies.uif.component.UIFLabel
Parameters:
g - Graphics object for painting


Copyright © 2000-2008 JGoodies Karsten Lentzsch. All Rights Reserved.