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?