com.jgoodies.uif.component
Class UIFMenuItem
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JMenuItem
com.jgoodies.uif.component.UIFMenuItem
- All Implemented Interfaces:
- ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants
public final class UIFMenuItem
- extends JMenuItem
A JMenuItem
subclass that adds supports for temporarily
invisible icons. Useful to hide icons on a specific platform or
for a specific look&feel. For example the Mac Aqua style guide
recommend to hide icons unless there's a special context such as
a history menu.
The menu item's icon set can be made visible or invisible directly.
But typically you should set the icon visible mode and use a
Mode
that describes when to
- Version:
- $Revision: 1.7 $
- Author:
- Karsten Lentzsch
- See Also:
Mode
,
Modes
,
Serialized Form
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 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 |
Constructor Summary |
UIFMenuItem()
Constructs a menu item with no set text or icon. |
UIFMenuItem(Action action)
Constructs a menu item whose properties are taken from the
specified Action . |
UIFMenuItem(Icon icon)
Constructs a menu item with the specified icon. |
UIFMenuItem(String text)
Constructs a menu item with the specified text. |
UIFMenuItem(String text,
Icon icon)
Constructs a menu item with the specified text and icon. |
UIFMenuItem(String text,
Icon icon,
int mnemonic)
Constructs a menu item with the specified text, icon and
keyboard mnemonic. |
UIFMenuItem(String text,
int mnemonic)
Constructs a menu item with the specified text and
keyboard mnemonic. |
Method Summary |
protected void |
configurePropertiesFromAction(Action a)
In addition to the superclass behavior, this class
sets the displayed mnemonic index if and only if the
action provides one under key "mnemonicIndex" . |
Mode |
getIconVisibleMode()
Returns the current icon mode that determines
whether this item shows or hides an icon - if any. |
boolean |
isIconVisible()
Answers whether icons are currently visible or hidden. |
static void |
setDisplayedMnemonicIndex(JMenuItem menuItem,
Action action)
Sets the menu item's display mnemonic index using the index value as
provided by the given action under key "mnemonicIndex" . |
void |
setIconVisible(boolean newVisible)
Shows or hides this item's icons. |
void |
setIconVisibleMode(Mode newMode)
Sets a new icon visible mode that determines whether
this item shows or hides an icon - if any. |
void |
updateUI()
In addition to the superclass behavior that updates the UI
this method adds or removes the item's icon according to the
icon visible mode's current enabled value - if any. |
Methods inherited from class javax.swing.JMenuItem |
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getAccessibleContext, getComponent, getMenuDragMouseListeners, getMenuKeyListeners, getSubElements, getUIClassID, init, isArmed, menuSelectionChanged, paramString, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setAccelerator, setArmed, setEnabled, setModel, setUI |
Methods inherited from class javax.swing.AbstractButton |
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, 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, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, 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, paint, paintChildren, paintComponent, 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, setBorder, 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, 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 |
UIFMenuItem
public UIFMenuItem()
- Constructs a menu item with no set text or icon.
UIFMenuItem
public UIFMenuItem(Icon icon)
- Constructs a menu item with the specified icon.
- Parameters:
icon
- the icon of the menu item
UIFMenuItem
public UIFMenuItem(String text)
- Constructs a menu item with the specified text.
- Parameters:
text
- the text of the menu item
UIFMenuItem
public UIFMenuItem(Action action)
- Constructs a menu item whose properties are taken from the
specified
Action
.
- Parameters:
action
- the action that provides the properties
UIFMenuItem
public UIFMenuItem(String text,
Icon icon)
- Constructs a menu item with the specified text and icon.
- Parameters:
text
- the text of the menu itemicon
- the icon of the menu item
UIFMenuItem
public UIFMenuItem(String text,
int mnemonic)
- Constructs a menu item with the specified text and
keyboard mnemonic.
- Parameters:
text
- the text of the menu itemmnemonic
- the keyboard mnemonic for the menu item
UIFMenuItem
public UIFMenuItem(String text,
Icon icon,
int mnemonic)
- Constructs a menu item with the specified text, icon and
keyboard mnemonic.
- Parameters:
text
- the text of the menu itemicon
- the icon of the menu itemmnemonic
- the keyboard mnemonic for the menu item
isIconVisible
public boolean isIconVisible()
- Answers whether icons are currently visible or hidden.
- Returns:
- true if icons are visible, false if invisible
setIconVisible
public void setIconVisible(boolean newVisible)
- Shows or hides this item's icons. In case the icons are hidden
they are stored in private fields so they can be restored later.
The current implementations override icons during the restoring proces
that have been set between the hide and show actions.
- Parameters:
newVisible
- true for visible, false for invisible
getIconVisibleMode
public Mode getIconVisibleMode()
- Returns the current icon mode that determines
whether this item shows or hides an icon - if any.
- Returns:
- the current icon mode
setIconVisibleMode
public void setIconVisibleMode(Mode newMode)
- Sets a new icon visible mode that determines whether
this item shows or hides an icon - if any.
- Parameters:
newMode
- the icon visible mode to be set
configurePropertiesFromAction
protected void configurePropertiesFromAction(Action a)
- In addition to the superclass behavior, this class
sets the displayed mnemonic index if and only if the
action provides one under key
"mnemonicIndex"
.
- Overrides:
configurePropertiesFromAction
in class JMenuItem
- Parameters:
a
- the Action
from which to get the properties,
or null
- See Also:
Action
updateUI
public void updateUI()
- In addition to the superclass behavior that updates the UI
this method adds or removes the item's icon according to the
icon visible mode's current enabled value - if any.
- Overrides:
updateUI
in class JMenuItem
setDisplayedMnemonicIndex
public static void setDisplayedMnemonicIndex(JMenuItem menuItem,
Action action)
- Sets the menu item's display mnemonic index using the index value as
provided by the given action under key
"mnemonicIndex"
.
TODO: Java 6.0 hopefully has the Action key included.
- Parameters:
menuItem
- the menu item to set a mnemonic indexaction
- the Action to read the mnemonic index from
Copyright © 2000-2008 JGoodies Karsten Lentzsch. All Rights Reserved.