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

MenuBar in SubScene does not work

XMLWordPrintable

      As discussed in RT-37855, there are some methods incorrectly using localToScene method.
      Some of them break the MenuBar functionality when in SubScene:

      public class MenuBarInSubScene extends Application {

          private static SubScene createSubScene(Paint fillPaint) {
              Group root = new Group();
              root.getChildren().add(someNodes());

              SubScene subScene = new SubScene(root, 150, 150);
              subScene.setFill(fillPaint);
              return subScene;
          }

          private static Parent someNodes() {
              final VBox vbox = new VBox();

              MenuBar bar = new MenuBar();
              final Menu foo = new Menu("Foo");
              foo.getItems().addAll(new MenuItem("X"), new MenuItem("Y"));
              bar.getMenus().addAll(foo, new Menu("Bar"));

              vbox.getChildren().add(bar);

              return vbox;
          }

          @Override
          public void start(Stage stage) {
              Group root = new Group();

              HBox hbox = new HBox();
              hbox.setTranslateY(50);
              root.getChildren().add(hbox);

              Scene scene = new Scene(root);

              SubScene plainSubScene = createSubScene(Color.GOLD);
              SubScene subSubScene = createSubScene(Color.SILVER);
              subSubScene.setHeight(75);
              subSubScene.setTranslateY(75);
              ((Group)plainSubScene.getRoot()).getChildren().add(subSubScene);
              hbox.getChildren().add(plainSubScene);

              Camera camera = new PerspectiveCamera();
              scene.setCamera(camera);
              stage.setScene(scene);
              stage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }

      }

            msladecek Martin Sládeček
            msladecek Martin Sládeček
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: