Top Description Fields Constructors Methods
javafx.scene.control.skin

public Class MenuBarSkin

extends SkinBase<MenuBar>
Class Inheritance
Imports
java.lang.ref.Reference, .WeakReference, java.util.ArrayList, .Collections, .Iterator, .List, .Map, .Optional, .WeakHashMap, java.util.stream.Collectors, javafx.application.Platform, javafx.beans.InvalidationListener, javafx.beans.property.DoubleProperty, .ObjectProperty, .ReadOnlyProperty, javafx.beans.value.ChangeListener, .WeakChangeListener, javafx.collections.ListChangeListener, .MapChangeListener, .ObservableList, javafx.css.CssMetaData, .Styleable, .StyleableDoubleProperty, .StyleableObjectProperty, .StyleableProperty, javafx.css.converter.EnumConverter, .SizeConverter, javafx.event.ActionEvent, .EventHandler, javafx.geometry.Bounds, .NodeOrientation, .Pos, javafx.scene.AccessibleAttribute, .Node, .Scene, javafx.scene.control.Control, .CustomMenuItem, .Menu, .MenuBar, .MenuButton, .MenuItem, .SeparatorMenuItem, .Skin, .SkinBase, javafx.scene.input.KeyCode, .KeyCombination, .KeyEvent, .MouseEvent, javafx.scene.layout.HBox, javafx.stage.Stage, .Window, javafx.util.Pair, .Subscription, com.sun.javafx.menu.MenuBase, com.sun.javafx.scene.ParentHelper, .SceneHelper, com.sun.javafx.scene.control.GlobalMenuAdapter, .IDisconnectable, .ListenerHelper, .MenuBarButton, com.sun.javafx.scene.traversal.Direction, .ParentTraversalEngine, com.sun.javafx.tk.Toolkit

Default skin implementation for the MenuBar control. In essence it is a simple toolbar. For the time being there is no overflow behavior and we just hide nodes which fall outside the bounds.
Since
9
See Also
MenuBar

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<MenuBar, Pos>
private boolean
private final HBox
container

contains MenuBarButton's children only

private ObjectProperty<Pos>
containerAlignment

Specifies the alignment of the menu buttons inside the MenuBar (by default it is Pos.TOP_LEFT).

private static Stage
pack-priv Runnable
private int
focusedMenuIndex

index of *focused* MenuBarButton

private Menu
private MenuBarButton
private boolean
private ChangeListener<Scene>
private ListenerHelper
private DoubleProperty
spacing

Specifies the spacing between menu buttons on the MenuBar.

private static final CssMetaData<MenuBar, Number>
private static final ObservableList<Window>
private static final List<CssMetaData<? extends Styleable, ?>>
private static WeakHashMap<Stage, Reference<MenuBarSkin>>
private WeakChangeListener<Boolean>
private WeakChangeListener<Boolean>
private IDisconnectable
private volatile Subscription
private static List<MenuBase>
private List<MenuBase>

Constructor Summary

AccessConstructor and Description

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
protected double
computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMaxHeight.

Computes the maximum allowable height of the Skin, based on the provided width.

protected double
computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMinHeight.

Computes the minimum allowable height of the Skin, based on the provided width.

protected double
computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMinWidth.

Computes the minimum allowable width of the Skin, based on the provided height.

protected double
computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computePrefHeight.

Calculates the preferred height of this SkinBase.

protected double
computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computePrefWidth.

Calculates the preferred width of this SkinBase.

public final ObjectProperty<Pos>
public void
dispose()

Overrides javafx.scene.control.SkinBase.dispose.

Implements javafx.scene.control.Skin.dispose.

Called when a previously installed skin is about to be removed from its associated control.

private Optional<Pair<Menu, Integer>>
findSibling(Direction dir, int startIndex)

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData associated with this class, which may include the CssMetaData of its superclasses
getClassCssMetaData
()

Hides javafx.scene.control.SkinBase.getClassCssMetaData.

Returns the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public final Pos
public List<CssMetaData<? extends Styleable, ?>>
getCssMetaData()

Overrides javafx.scene.control.SkinBase.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

pack-priv int
private int
private static MenuBarSkin
public final double
private static void
private boolean
protected void
layoutChildren(final double x, final double y, final double w, final double h)

Overrides javafx.scene.control.SkinBase.layoutChildren.

Called during the layout pass of the scenegraph.

private void
moveToMenu(Direction dir, boolean doShow)

protected Object
queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.control.SkinBase.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

private void
private void
public final void
public static void
setDefaultSystemMenuBar(final MenuBar
the menu bar
menuBar
)

Set the default system menu bar.

pack-priv void
setFocusedMenuIndex(int index)

This method is package scoped as it is used in this class as well as for testing

public final void
setSpacing(double value)

private static void
private void
showMenu(Menu menu)

private void
showMenu(Menu menu, boolean selectFirstItem)

protected double
snappedBottomInset()

Overrides javafx.scene.control.SkinBase.snappedBottomInset.

Utility method to get the bottom inset which includes padding and border inset.

protected double
snappedLeftInset()

Overrides javafx.scene.control.SkinBase.snappedLeftInset.

Utility method to get the left inset which includes padding and border inset.

protected double
snappedRightInset()

Overrides javafx.scene.control.SkinBase.snappedRightInset.

Utility method to get the right inset which includes padding and border inset.

protected double
snappedTopInset()

Overrides javafx.scene.control.SkinBase.snappedTopInset.

Utility method to get the top inset which includes padding and border inset.

public final DoubleProperty
private void
private void
updateActionListeners(MenuItem item, boolean add)

private void
Inherited from javafx.scene.control.SkinBase:
computeBaselineOffsetcomputeMaxWidthconsumeMouseEventsexecuteAccessibleActiongetChildrengetNodegetSkinnablelayoutInArealayoutInArealayoutInAreapositionInAreapositionInAreapseudoClassStateChangedregisterChangeListenerregisterInvalidationListenerregisterListChangeListenersnapPositionsnapPositionXsnapPositionYsnapSizesnapSizeXsnapSizeYsnapSpacesnapSpaceXsnapSpaceYunregisterChangeListenersunregisterInvalidationListenersunregisterListChangeListeners

Field Detail

ALIGNMENTback to summary
private static final CssMetaData<MenuBar, Pos> ALIGNMENT
altKeyPressedback to summary
private boolean altKeyPressed
containerback to summary
private final HBox container

contains MenuBarButton's children only

containerAlignmentback to summary
private ObjectProperty<Pos> containerAlignment

Specifies the alignment of the menu buttons inside the MenuBar (by default it is Pos.TOP_LEFT).

currentMenuBarStageback to summary
private static Stage currentMenuBarStage
firstMenuRunnableback to summary
pack-priv Runnable firstMenuRunnable
focusedMenuIndexback to summary
private int focusedMenuIndex

index of *focused* MenuBarButton

openMenuback to summary
private Menu openMenu
openMenuButtonback to summary
private MenuBarButton openMenuButton
pendingDismissback to summary
private boolean pendingDismiss
sceneChangeListenerback to summary
private ChangeListener<Scene> sceneChangeListener
sceneListenerHelperback to summary
private ListenerHelper sceneListenerHelper
spacingback to summary
private DoubleProperty spacing

Specifies the spacing between menu buttons on the MenuBar.

SPACINGback to summary
private static final CssMetaData<MenuBar, Number> SPACING
stagesback to summary
private static final ObservableList<Window> stages
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES
systemMenuMapback to summary
private static WeakHashMap<Stage, Reference<MenuBarSkin>> systemMenuMap
weakMenuBarFocusedPropertyListenerback to summary
private WeakChangeListener<Boolean> weakMenuBarFocusedPropertyListener
weakMenuVisibilityChangeListenerback to summary
private WeakChangeListener<Boolean> weakMenuVisibilityChangeListener
windowFocusHelperback to summary
private IDisconnectable windowFocusHelper
windowSubscriptionback to summary
private volatile Subscription windowSubscription
wrappedDefaultMenusback to summary
private static List<MenuBase> wrappedDefaultMenus
wrappedMenusback to summary
private List<MenuBase> wrappedMenus

Constructor Detail

Method Detail

cleanUpListenersback to summary
private void cleanUpListeners()
cleanUpSystemMenuback to summary
private void cleanUpSystemMenu()
clearMenuButtonHoverback to summary
private void clearMenuButtonHover()
computeMaxHeightback to summary
protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMaxHeight.

Doc from javafx.scene.control.SkinBase.computeMaxHeight.

Computes the maximum allowable height of the Skin, based on the provided width.

Annotations
@Override
computeMinHeightback to summary
protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMinHeight.

Doc from javafx.scene.control.SkinBase.computeMinHeight.

Computes the minimum allowable height of the Skin, based on the provided width.

Annotations
@Override
computeMinWidthback to summary
protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMinWidth.

Doc from javafx.scene.control.SkinBase.computeMinWidth.

Computes the minimum allowable width of the Skin, based on the provided height.

Annotations
@Override
computePrefHeightback to summary
protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computePrefHeight.

Doc from javafx.scene.control.SkinBase.computePrefHeight.

Calculates the preferred height of this SkinBase. The default implementation calculates this height as the height of the area occupied by its managed children when they are positioned at their current positions at their preferred heights.

Annotations
@Override
computePrefWidthback to summary
protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computePrefWidth.

Doc from javafx.scene.control.SkinBase.computePrefWidth.

Calculates the preferred width of this SkinBase. The default implementation calculates this width as the width of the area occupied by its managed children when they are positioned at their current positions at their preferred widths.

Annotations
@Override
containerAlignmentPropertyback to summary
public final ObjectProperty<Pos> containerAlignmentProperty()
disposeback to summary
public void dispose()

Overrides javafx.scene.control.SkinBase.dispose.

Implements javafx.scene.control.Skin.dispose.

Doc from javafx.scene.control.SkinBase.dispose.

Called when a previously installed skin is about to be removed from its associated control. This allows the skin to do clean up, like removing listeners and bindings, and undo any changes to the control's properties. After this method completes, getSkinnable() and getNode() should return null.

Calling dispose() more than once has no effect.

Annotations
@Override
findSiblingback to summary
private Optional<Pair<Menu, Integer>> findSibling(Direction dir, int startIndex)
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.SkinBase.getClassCssMetaData.

Returns the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData associated with this class, which may include the CssMetaData of its superclasses

getContainerAlignmentback to summary
public final Pos getContainerAlignment()
getCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData()

Overrides javafx.scene.control.SkinBase.getCssMetaData.

Doc from javafx.scene.control.SkinBase.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

Annotations
@Override
getFocusedMenuIndexback to summary
pack-priv int getFocusedMenuIndex()
getMenuBarButtonIndexback to summary
private int getMenuBarButtonIndex(MenuBarButton m)
getMenuBarSkinback to summary
private static MenuBarSkin getMenuBarSkin(Stage stage)
getSpacingback to summary
public final double getSpacing()
initSystemMenuBarback to summary
private static void initSystemMenuBar()
isMenuEmptyback to summary
private boolean isMenuEmpty(Menu menu)
layoutChildrenback to summary
protected void layoutChildren(final double x, final double y, final double w, final double h)

Overrides javafx.scene.control.SkinBase.layoutChildren.

Doc from javafx.scene.control.SkinBase.layoutChildren.

Called during the layout pass of the scenegraph.

Annotations
@Override
moveToMenuback to summary
private void moveToMenu(Direction dir, boolean doShow)
queryAccessibleAttributeback to summary
protected Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.control.SkinBase.queryAccessibleAttribute.

Doc from javafx.scene.control.SkinBase.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

This method is commonly overridden by subclasses to implement attributes that are required for a specific role.
If a particular attribute is not handled, the superclass implementation must be called.

Annotations
@Override
rebuildUIback to summary
private void rebuildUI()
resetOpenMenuback to summary
private void resetOpenMenu()
setContainerAlignmentback to summary
public final void setContainerAlignment(Pos value)
setDefaultSystemMenuBarback to summary
public static void setDefaultSystemMenuBar(final MenuBar menuBar)

Set the default system menu bar. This allows an application to keep menu in the system menu bar after the last Window is closed.

Parameters
menuBar:MenuBar

the menu bar

setFocusedMenuIndexback to summary
pack-priv void setFocusedMenuIndex(int index)

This method is package scoped as it is used in this class as well as for testing

setSpacingback to summary
public final void setSpacing(double value)
setSystemMenuback to summary
private static void setSystemMenu(Stage stage)
showMenuback to summary
private void showMenu(Menu menu)
showMenuback to summary
private void showMenu(Menu menu, boolean selectFirstItem)
snappedBottomInsetback to summary
protected double snappedBottomInset()

Overrides javafx.scene.control.SkinBase.snappedBottomInset.

Doc from javafx.scene.control.SkinBase.snappedBottomInset.

Utility method to get the bottom inset which includes padding and border inset. Then snapped to whole pixels if getSkinnable().isSnapToPixel() is true.

Annotations
@Override
snappedLeftInsetback to summary
protected double snappedLeftInset()

Overrides javafx.scene.control.SkinBase.snappedLeftInset.

Doc from javafx.scene.control.SkinBase.snappedLeftInset.

Utility method to get the left inset which includes padding and border inset. Then snapped to whole pixels if getSkinnable().isSnapToPixel() is true.

Annotations
@Override
snappedRightInsetback to summary
protected double snappedRightInset()

Overrides javafx.scene.control.SkinBase.snappedRightInset.

Doc from javafx.scene.control.SkinBase.snappedRightInset.

Utility method to get the right inset which includes padding and border inset. Then snapped to whole pixels if getSkinnable().isSnapToPixel() is true.

Annotations
@Override
snappedTopInsetback to summary
protected double snappedTopInset()

Overrides javafx.scene.control.SkinBase.snappedTopInset.

Doc from javafx.scene.control.SkinBase.snappedTopInset.

Utility method to get the top inset which includes padding and border inset. Then snapped to whole pixels if getSkinnable().isSnapToPixel() is true.

Annotations
@Override
spacingPropertyback to summary
public final DoubleProperty spacingProperty()
unSelectMenusback to summary
private void unSelectMenus()
updateActionListenersback to summary
private void updateActionListeners(MenuItem item, boolean add)
updateFocusedIndexback to summary
private void updateFocusedIndex()