Class JPopupMenu

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

public class JPopupMenu extends JComponent implements Accessible, MenuElement
Emulator for JPopupMenu. R_leaf_peer_lockdown-locked over SJPopupMenu.
See Also:
  • Constructor Details

    • JPopupMenu

      public JPopupMenu()
    • JPopupMenu

      public JPopupMenu(String label)
  • Method Details

    • add

      public JMenuItem add(JMenuItem item)
    • add

      public JMenuItem add(String text)
    • add

      public JMenuItem add(Action a)
    • addSeparator

      public void addSeparator()
    • insert

      public void insert(JMenuItem item, int index)
    • insert

      public void insert(Action a, int index)
    • remove

      public void remove(JMenuItem item)
    • remove

      public void remove(int index)
      Overrides:
      remove in class Container
    • removeAll

      public void removeAll()
      Overrides:
      removeAll in class Container
    • getComponentCount

      public int getComponentCount()
      JDK inherits Container.getComponentCount(); since our menu children live in this list (not via Container.addImpl, per D_menu_tree), override so the count reflects the JDK menu tree.
      Overrides:
      getComponentCount in class Container
    • getComponentIndex

      public int getComponentIndex(Component c)
    • setEnabled

      public void setEnabled(boolean enabled)
      Overrides:
      setEnabled in class JComponent
    • show

      public void show(Component invoker, int x, int y)
      Binds the popup to invoker so a right-click (or long-press) on it opens the menu, then ends in setVisible(true) as the JDK's own body does. The coordinates are dropped — R_layouts_close_enough position loss, and Vaadin has no programmatic open at a point (SD_sjpopupmenu); the common right-click-triggered idiom works natively once the target is bound.

      Calling setVisible(true) here cannot double-fire against the browser's own open in the same round trip: whichever of the two lands first writes the state, and the other hits a no-change early return, so exactly one willBecomeVisible reaches the migrator either way.

    • setVisible

      public void setVisible(boolean visible)
      Shows or hides the popup, firing the JDK's notifications either way.

      The two directions are not symmetric, because Vaadin's ContextMenu is not: it has a close() but no server-side programmatic open, so hiding really hides while showing is a declined effect (R_match_swing_errors sub-bucket (a) — graduates if upstream lands one). R_decline_effect_only keeps the state and the notification either way, so a migrator's PopupMenuListener and "visible" listener fire where they fire on the desktop.

      The only gate is b == isVisible() — no displayability check and no invoker needed, a bare new JPopupMenu().setVisible(true) reporting true on JDK 25 (measured).

      Two things the JDK's hide path also does are absent: firePopupMenuCanceled(), reachable only through the client property its L&F sets, and the selection-model clear, MenuSelectionManager being a WARN-stub with no selection to clear.

      Overrides:
      setVisible in class JComponent
    • isVisible

      public boolean isVisible()
      Overrides:
      isVisible in class Component
      Returns:
      whether the popup is open — the JDK's popup != null, written by setVisible(boolean) and by the browser's own open/close alike. Not read off the peer, which would have the getter deny the state a declined programmatic open still owes (R_decline_effect_only).
    • getLabel

      public String getLabel()
    • setLabel

      public void setLabel(String label)
    • pack

      public void pack()
    • setInvoker

      public void setInvoker(Component invoker)
    • isLightWeightPopupEnabled

      public boolean isLightWeightPopupEnabled()
    • setLightWeightPopupEnabled

      public void setLightWeightPopupEnabled(boolean enabled)
      Stores the flag; the popup renders as a Vaadin DOM overlay either way, which is the effect R_decline_effect_only permits dropping. The state is not — a migrated app that reads the flag back must see what it set.
    • getSubElements

      public MenuElement[] getSubElements()
      Specified by:
      getSubElements in interface MenuElement
    • getComponent

      public Component getComponent()
      Specified by:
      getComponent in interface MenuElement
      Returns:
      this — the JDK's own answer. See JMenuItem.getComponent() for why the ported MenuElement is what makes that possible.
    • processKeyEvent

      public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
      Specified by:
      processKeyEvent in interface MenuElement
    • processMouseEvent

      public void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
      Specified by:
      processMouseEvent in interface MenuElement
    • addPopupMenuListener

      public void addPopupMenuListener(PopupMenuListener l)
    • removePopupMenuListener

      public void removePopupMenuListener(PopupMenuListener l)
    • getPopupMenuListeners

      public PopupMenuListener[] getPopupMenuListeners()
    • firePopupMenuWillBecomeVisible

      protected void firePopupMenuWillBecomeVisible()
    • firePopupMenuWillBecomeInvisible

      protected void firePopupMenuWillBecomeInvisible()
    • firePopupMenuCanceled

      protected void firePopupMenuCanceled()
      JDK-shaped notifier, kept for the API surface but never reached: the JDK's callers are L&F machinery (dropped per R_match_swing_errors sub-bucket (b)), and the peer's OpenedChangeEvent cannot distinguish a cancel (Esc, click-outside) from an item-selection close — both arrive as opened=false and fire willBecomeInvisible only. A migrator's override compiles and does not run; documented rather than guessed at, since a heuristic would invent cancels the desktop never fired (R_no_silent_improvements).
    • getUIClassID

      public String getUIClassID()
      Overrides:
      getUIClassID in class JComponent
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JComponent
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()
      Specified by:
      getAccessibleContext in interface Accessible
      Overrides:
      getAccessibleContext in class Component