Java examples for JavaFX:Menu
Configures a JavaFX MenuItem with the specified action.
/*//from www . j a va 2 s . c om * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Notice * * The contents of this file are subject to the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. A copy of the License is available at * http://www.opensource.org/licenses/cddl1.txt * * The Original Code is Drombler.org. The Initial Developer of the * Original Code is Florian Brunner (Sourceforge.net user: puce). * Copyright 2012 Drombler.org. All Rights Reserved. * * Contributor(s): . */ import javafx.scene.Node; import javafx.scene.control.CheckMenuItem; import javafx.scene.control.MenuItem; import javafx.scene.control.RadioMenuItem; public class Main{ /** * Configures a {@link MenuItem} with the specified action. * * @param menuItem the menu item to configre * @param action the action * @param iconSize the icon size */ public static void configureMenuItem(MenuItem menuItem, FXAction action, int iconSize) { menuItem.setMnemonicParsing(true); menuItem.textProperty().bind(action.displayNameProperty()); menuItem.acceleratorProperty().bind(action.acceleratorProperty()); menuItem.setOnAction(action); menuItem.disableProperty().bind(action.enabledProperty().not()); if (action.getGraphicFactory() != null) { Node graphic = action.getGraphicFactory().createGraphic( iconSize); if (graphic != null) { menuItem.setGraphic(graphic); } } } }