Class SJMenuBar
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.menubar.MenuBar
com.vaadin.swingbridge.surrogates.SJMenuBar
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.contextmenu.HasMenuItems, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.menubar.MenuBarVariant>, ComponentMixin, ContainerMixin, JComponentMixin, Serializable
Surrogate for
JMenuBar (SD_sjmenubar). Extends Vaadin
MenuBar directly and reproduces the Swing menubar surface via a
tree-rebuild API that the emulator-side :emulators.swing.JMenuBar
pushes through on every JDK menu-tree mutation.
Why MenuBar, asymmetric split
VaadinMenuItem's ctor is effectively package-private (it requires
a Vaadin-internal ContextMenu owner + content-reset callback), so
a surrogate cannot extend it as SJMenuItem extends MenuItem and
substitute it where Vaadin's own addItem would return one. The
smallest surrogate-layer unit that's a true Vaadin Component is therefore
the whole bar, not the individual items. R_vaadin_first then says don't ship a
parallel SJMenu / SJMenuItem surface that exists only to
mirror JDK shape — pure-surrogate users compose with
MenuBar.addItem(String, com.vaadin.flow.component.ComponentEventListener)
directly.
Tree-rebuild API
The emulator walks its JDK tree and pushes aList<MenuNode>
snapshot via rebuildFromTree(List). The actual Vaadin-side walk
lives in the shared MenuTreeBuilder (SD_sjpopupmenu — same engine
SJPopupMenu uses, keyed on Vaadin's HasMenuItems). Click
handlers funnel through SHelper.callSwing(Runnable) (R_callswing_envelope).
Top-level separators + mnemonics: drop-and-WARN R_vaadin_first
VaadinMenuBar doesn't expose top-level addSeparator()
(separators only land inside a SubMenu); the rebuild's top-level
separator callback logs via SHelper.onUnimplemented(Object, String, Object...) and skips.
(SJPopupMenu's ContextMenu peer does support
top-level separators — that's the one asymmetry the shared builder's
per-caller callback covers.) Top-level mnemonics have no Vaadin
counterpart either. Both are R_match_swing_errors sub-bucket (a).
Accelerators
Per-itemKeyStroke accelerators install as UI-scoped
Shortcuts bindings via
MenuTreeBuilder.installAccelerators(UI, Component, Map, Map). Each rebuild tears the old
registrations down before installing fresh ones, keyed by JDK
KeyStroke in MenuBarStateStore.acceleratorRegistrations.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.menubar.MenuBar
com.vaadin.flow.component.menubar.MenuBar.MenuBarI18nNested classes/interfaces inherited from interface JComponentMixin
JComponentMixin.ActionStandin -
Field Summary
Fields inherited from interface JComponentMixin
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConvenience accessor for tests + diagnostics — returns the most recently pushedMenuNodesnapshot.JDK matches"MenuBarUI".protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) Re-install accelerators on attach.voidrebuildFromTree(List<MenuNode> tree) Push a fresh JDK menu-tree snapshot through to the Vaadin MenuBar.Methods inherited from class com.vaadin.flow.component.menubar.MenuBar
addItem, addItem, addItem, addItem, addItem, addItem, addItem, addItem, close, getChildren, getI18n, getItems, isOpenOnHover, isReverseCollapseOrder, isTabNavigation, remove, removeAll, setI18n, setOpenOnHover, setReverseCollapseOrder, setTabNavigation, setTooltipTextMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface ComponentMixin
_installSwingClass, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, dispatchEvent, doLayout, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getComponentListeners, getCursor, getFocusListeners, getFont, getForeground, getGraphics, getHierarchyBoundsListeners, getHierarchyListeners, getKeyListeners, getLocation, getMaximumSize, getMinimumSize, getMouseListeners, getName, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolTipText, getX, getY, grabFocus, hasFocus, invalidate, isDisplayable, isFocusable, isFocusOwner, isShowing, paint, paintAll, print, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, revalidate, setBackground, setBounds, setBounds, setCursor, setFocusable, setFont, setForeground, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validateMethods inherited from interface ContainerMixin
addContainerListener, getContainerListeners, getLayout, paintComponents, printComponents, removeContainerListener, setLayoutMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, bindThemeVariant, bindThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariantsMethods inherited from interface JComponentMixin
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, isDoubleBuffered, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, requestDefaultFocus, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, updateUI
-
Constructor Details
-
SJMenuBar
public SJMenuBar()
-
-
Method Details
-
rebuildFromTree
Push a fresh JDK menu-tree snapshot through to the Vaadin MenuBar. A snapshot that changes only checked states, handlers or accelerators updates the existing items (MenuTreeBuilder.patchInPlace(List, List, List)); anything else tears the tree down and rebuilds it. Accelerators are reinstalled either way.The
preventRebuildre-entrancy guard short-circuits recursive calls — a click handler that runs as part of this rebuild (toggle-item commit, etc.) firing back into the emulator can't cascade into another nested rebuild.nullor empty tree fully clears the menubar. -
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) Re-install accelerators on attach. The firstrebuildFromTreecall may run before the menubar is attached (e.g. building the bar in a JFrame ctor beforesetVisible(true)); the install pass skips silently in that case. This hook re-walks the current tree once the UI exists.- Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
getCurrentTree
-
getUIClassID
JDK matches"MenuBarUI".- Specified by:
getUIClassIDin interfaceJComponentMixin
-