简体   繁体   中英

Java(FX): How can I edit the menu items of the standard mac os x menu bar?

I'm developing a Java(FX) application and like to change the title of my application in the standard menu item of every application (see the screenshot). I also want to set an own behavior for the About and Preferences menu items, but they arn't there.

屏幕截图:TextWrangler的标准菜单项

I know, that this is possible in swing, but how it is possible with! JavaFX?

You can use NSMenuFX to do this. Here is an example on how to create an About menu:

NSMenuBarAdapter adapter = new NSMenuBarAdapter();

// Get the default menu bar as JavaFX object
MenuBar menuBar = adapter.getMenuBar();

// Create a new menu item
MenuItem about = new MenuItem("About");

about.setOnAction(new EventHandler<ActionEvent>() {
  @Override
  public void handle(ActionEvent event) {
    // Open a new JavaFX dialog
  }
});

// Add the menu item as first element to the application menu
menuBar.getMenus().get(0).getItems().add(0, about);

// Update the menu bar
adapter.setMenuBar(menuBar);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM