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

Mac: systemMenuBar's menus can not be renamed.

    XMLWordPrintable

    Details

      Description

      Run the code:

      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.TextArea;
      import javafx.scene.control.ToggleButton;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class JavaFXApplication5 extends Application {

          public final static String USESYSTEM_BTN_ID = "Use system menu bar";
          public final static int MENUS_NUM = 3;
          public final static int MENUS_DEPTH = 1;
          VBox root;
          Label lastSelected;
          TextArea event_log;

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

          @Override
          public void start(Stage stage) throws Exception {
              stage.setScene(new MenuBarAppScene());
              stage.show();
          }

          private class BarItem extends Menu {

              public BarItem(String str, int depth) {
                  super(str);
                  addSubMenu(this, depth - 1);
              }

              private void addSubMenu(MenuItem root, int level) {
                  for (int i = 0; i < MENUS_NUM; i++) {
                      final MenuItem item;
                      if (level > 0) {
                          item = new Menu(root.getText() + " SubMenu " + i);
                      } else {
                          item = new MenuItem(root.getText() + " MenuItem " + i);
                      }
                      item.setOnAction(new EventHandler<ActionEvent>() {
                          public void handle(ActionEvent t) {
                              lastSelected.setText(item.getText());
                          }
                      });
                      ((Menu) root).getItems().add(item);
                      if (level > 0) {
                          addSubMenu(item, level - 1);
                      }
                  }
              }
          }

          public class MenuBarAppScene extends Scene {

              final MenuBar bar;

              public MenuBarAppScene() {
                  super(root = new VBox(5));

                  lastSelected = new Label();

                  Pane test_pane = new Pane();
                  test_pane.setPrefSize(600, 300);
                  test_pane.setMaxSize(600, 300);
                  root.getChildren().add(test_pane);

                  bar = new MenuBar();
                  test_pane.getChildren().add(bar);
                  reset();



                  ToggleButton use_system = new ToggleButton(USESYSTEM_BTN_ID);
                  use_system.setId(USESYSTEM_BTN_ID);
                  use_system.selectedProperty().addListener(new ChangeListener<Boolean>() {
                      public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                          bar.setUseSystemMenuBar(t1);
                      }
                  });

                  Button renamingButton = new Button("Rename");
                  renamingButton.setOnAction(new EventHandler<ActionEvent>() {
                      public void handle(ActionEvent t) {
                          bar.getMenus().get(1).setText("Renamed " + bar.getMenus().get(1).getText());
                          bar.getMenus().get(0).getItems().get(0).setText("Renamed " + bar.getMenus().get(0).getItems().get(0).getText());
                          bar.getMenus().get(2).getItems().get(2).setText("Renamed " + bar.getMenus().get(2).getItems().get(2).getText());
                      }
                  });


                  VBox controls = new VBox(5);
                  root.getChildren().add(controls);
                  controls.getChildren().addAll(use_system, renamingButton);
              }

              protected final void reset() {
                  bar.getMenus().clear();
                  for (int i = 0; i < MENUS_NUM; i++) {
                      bar.getMenus().add(new BarItem("Menu " + i, MENUS_DEPTH));
                  }
              }
          }
      }

      Set toggle "use system menu bar" to true.
      click button rename.
      "Menu 1" must be renamed to "Renamed Menu 1",
      but it didn't happen.

      You need to switch toggle "use system menu bar" to false and true again, to see the result.

        Attachments

          Activity

            People

            Assignee:
            smandalika Srinivas Mandalika
            Reporter:
            akirov Alexander Kirov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Imported: