Class IconActionableMenuItem

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants

public class IconActionableMenuItem extends JMenuItem
A JMenuItem whose icon reacts to clicks independently of the item's main action. Useful for entries that need a secondary action (e.g., a "reveal" or "info" shortcut) triggered only when the icon itself is clicked, leaving the rest of the item free to fire the default action. While hovered, the icon gets a hand cursor and a subtle highlight so it reads as its own clickable control.
Author:
Tiago Ferreira
See Also:
  • Constructor Details

    • IconActionableMenuItem

      public IconActionableMenuItem(String text, Icon icon)
  • Method Details

    • addIconActionListener

      public void addIconActionListener(ActionListener listener)
      Registers a listener fired only when this item's icon is clicked
    • removeIconActionListener

      public void removeIconActionListener(ActionListener listener)
    • setIconHoverIcon

      public void setIconHoverIcon(Icon icon)
      Sets an alternate icon shown in place of the default icon while the icon is hovered, instead of the translucent highlight rectangle used by default. null (the default) restores the highlight-rectangle behavior.
    • getIcon

      public Icon getIcon()
      Swaps in hoverIcon (if set) while the icon is hovered - resolved here, at the same place the UI delegate reads the icon to paint, rather than painting hoverIcon over the default icon in paint(Graphics): painting both would blend them wherever hoverIcon isn't fully opaque (glyph icons are mostly transparent outside their strokes), whereas resolving the icon here means only one is ever drawn per paint pass.
      Overrides:
      getIcon in class AbstractButton
    • paint

      public void paint(Graphics g)
      Overrides:
      paint in class JComponent
    • processMouseEvent

      protected void processMouseEvent(MouseEvent e)
      Overrides:
      processMouseEvent in class JComponent