Global Menu for JavaFX Applications
I know that we can enable global menu for Java Swing applications using Jayatana. But I am searching for global menu support for JavaFX applications. After searching on it, I have found that setUseSystemMenuBar is used in JavaFX to enable same kind of behavior in Mac. But it is not working in Ubuntu.
My Java code:
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.stage.*;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 300, 250, Color.WHITE);
MenuBar menuBar = new MenuBar();
// Use system menu bar
menuBar.setUseSystemMenuBar(true);
menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
root.setTop(menuBar);
Menu fileMenu = new Menu("File");
Menu webMenu = new Menu("Web");
Menu sqlMenu = new Menu("SQL");
menuBar.getMenus().addAll(fileMenu, webMenu, sqlMenu);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Output:
Also there is a bug report regarding this problem here: Gtk: Implement global system menu bar support
Are there any workarounds to solve this problem?
Looking at the code, and I'm not an experienced FX developer, but it looks like the line "root.setTop(menuBar);" is locating the menu bar at the top of your container, not in the top row of the total display. I think some other command is necessary. I only have Java AWT and Swing experience and may be wrong.