Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8095227

Mac: useSystemMenuBar has no effect if using main() method to launch

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 8u5
    • javafx
    • Java 8u5 on Mac OS X 10.7.5 on Macbook Air; colleague gets same behaviour on 8u5 on Macbook Pro with Mavericks.

      I have an existing application that I am progressively adding JavaFX to. I have a Stage that I make with a menu, and I call setUseSystemMenuBar(true). However, on Mac this has no effect. I wonder if this could be fixed if possible, or if is intended behaviour that it does not work, if that could be documented somewhere. Steps to reproduce:

      // A class that creates a scene with a menu and sets useSystemMenuBar to true:
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.layout.VBox;

      public class MenuScene extends Scene
      {
          public MenuScene()
          {
              super(new VBox());
              MenuBar m = new MenuBar();
              Menu menu = new Menu("My Menu");
              menu.getItems().add(new MenuItem("My item"));
              m.getMenus().add(menu);
              m.setUseSystemMenuBar(true);
              
              ((VBox)getRoot()).getChildren().addAll(m, new Label("Content"));
          }
      }

      // It works if I call it from a JavaFX Application:
      import javafx.application.Application;
      import javafx.stage.Stage;

      public class TestPureMenu extends Application
      {
          @Override
          public void start(Stage stage) throws Exception
          {
              stage.setScene(new MenuScene());
              stage.show();
          }
      }

      // But not if I call it from an existing non-JavaFX application:
      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.stage.Stage;

      public class TestEmbedMenu
      {
          public static void main(String[] args) {
              // Initialise JavaFX:
              new JFXPanel();
              
              // Now make Stage:
              Platform.runLater(() -> {
                  Stage s = new Stage();
                  s.setScene(new MenuScene());
                  s.show();
              });
          }
      }

            anthony Anthony Petrov (Inactive)
            nbrownjfx Neil Brown (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: