This content has been marked as final. Show 1 reply
The skin isn't set on the control until the next pulse after the control has been added to the scene-graph. In other words, you cannot do
because the MenuBar has not yet been added to the scene-graph. Nor can you do
MenuBar menuBar = new MenuBar(); Skin skin = menuBar.getSkin();
because the skin isn't set until the next pulse. There are many ways you can get the skin. The easiest is to just set the skin yourself:
MenuBar menuBar = new MenuBar(); ((Group)scene.getRoot()).getChildren().add(menuBar); Skin skin = menuBar.getSkin();
Or you can add a listener to the skinProperty of the Control and grab it when it is set.
MenuBar menuBar = new MenuBar(); menuBar.setSkin(new com.sun.javafx.scene.control.skin.MenuBarSkin(menuBar));