Java Code Examples for javafx.scene.control.MenuButton#addEventHandler()
The following examples show how to use
javafx.scene.control.MenuButton#addEventHandler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomNavigationDrawerSkin.java From WorkbenchFX with Apache License 2.0 | 5 votes |
private MenuButton buildSubmenu(MenuItem item) { Menu menu = (Menu) item; MenuButton menuButton = new MenuButton(); menuButton.setPopupSide(Side.RIGHT); menuButton.graphicProperty().bind(menu.graphicProperty()); menuButton.textProperty().bind(menu.textProperty()); menuButton.disableProperty().bind(menu.disableProperty()); menuButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); menuButton.getStyleClass().addAll(item.getStyleClass()); Bindings.bindContent(menuButton.getItems(), menu.getItems()); // To determine if a TOUCH_RELEASED event happens. // The MOUSE_ENTERED results in an unexpected behaviour on touch events. // Event filter triggers before the handler. menuButton.addEventFilter(TouchEvent.TOUCH_RELEASED, e -> isTouchUsed = true); // Only when ALWAYS or SOMETIMES if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) { menuButton.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Menu if (isTouchUsed) { isTouchUsed = false; return; } // When ALWAYS, then trigger immediately. Else check if clicked before (case: SOMETIMES) if (Priority.ALWAYS.equals(getSkinnable().getMenuHoverBehavior()) || (hoveredBtn != null && hoveredBtn.isShowing())) { menuButton.show(); // Shows the context-menu if (hoveredBtn != null && hoveredBtn != menuButton) { hoveredBtn.hide(); // Hides the previously hovered Button if not null and not self } } hoveredBtn = menuButton; // Add the button as previously hovered }); } return menuButton; }
Example 2
Source File: NavigationDrawerSkin.java From WorkbenchFX with Apache License 2.0 | 5 votes |
private MenuButton buildSubmenu(MenuItem item) { Menu menu = (Menu) item; MenuButton menuButton = new MenuButton(); menuButton.setPopupSide(Side.RIGHT); menuButton.graphicProperty().bind(menu.graphicProperty()); menuButton.textProperty().bind(menu.textProperty()); menuButton.disableProperty().bind(menu.disableProperty()); menuButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); menuButton.getStyleClass().addAll(item.getStyleClass()); Bindings.bindContent(menuButton.getItems(), menu.getItems()); // To determine if a TOUCH_RELEASED event happens. // The MOUSE_ENTERED results in an unexpected behaviour on touch events. // Event filter triggers before the handler. menuButton.addEventFilter(TouchEvent.TOUCH_RELEASED, e -> isTouchUsed = true); // Only when ALWAYS or SOMETIMES if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) { menuButton.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Menu if (isTouchUsed) { isTouchUsed = false; return; } // When ALWAYS, then trigger immediately. Else check if clicked before (case: SOMETIMES) if (Priority.ALWAYS.equals(getSkinnable().getMenuHoverBehavior()) || (hoveredBtn != null && hoveredBtn.isShowing())) { menuButton.show(); // Shows the context-menu if (hoveredBtn != null && hoveredBtn != menuButton) { hoveredBtn.hide(); // Hides the previously hovered Button if not null and not self } } hoveredBtn = menuButton; // Add the button as previously hovered }); } return menuButton; }