1 Reply Latest reply: Jan 24, 2013 5:44 PM by David Grieve RSS

    How to set skin for Menu bar

    964914
      I am doing a get Skin from Menu bar, but it returns null. Is there a way to set the skin for menu bar. I tried other alternatives like setting new com.sun .java fx.sce ne .control.skin.Menu BarSkin() but it doesn't work.

      Please help.
        • 1. Re: How to set skin for Menu bar
          David Grieve
          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
          MenuBar menuBar  = new MenuBar();
          Skin skin = menuBar.getSkin();
          because the MenuBar has not yet been added to the scene-graph. Nor can you do
          MenuBar menuBar = new MenuBar();
          ((Group)scene.getRoot()).getChildren().add(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();
          menuBar.setSkin(new com.sun.javafx.scene.control.skin.MenuBarSkin(menuBar));
          Or you can add a listener to the skinProperty of the Control and grab it when it is set.