OSX System menubar not working in JavaFX

只愿长相守 提交于 2019-12-12 04:20:04

问题


I was trying to use NSMenuFX from https://github.com/codecentric/NSMenuFX to make a JavaFX app use the MacOS System MenuBar, and it didn't work because of this method returning always false.

Toolkit.getToolkit().getSystemMenu().isSupported()

The method is from the package : com.sun.javafx.tk.Toolkit.

Going deeper in the code I've found that Toolkit.getToolkit().getSystemMenu().isSupported() calls a method from com.sun.glass.ui.Application that returns always false too.

protected boolean _supportsSystemMenu() {
    return false;
}

public final boolean supportsSystemMenu() {
    checkEventThread();
    return this._supportsSystemMenu();
}

Is there something wrong about this code, and how can i get JavaFX app using the System menubar.

NB :Used JDK is 8u121 on OSX 10.12.3.

Edit 1 : As suggested in comments, here is some code.

import javafx.scene.control.MenuBar;

public class MyappMenuBar extends MenuBar {
// member variables -------------------------------------------------------------------------
    private final MyappPane mmyappPane;
    public MyappPane getMyappPane() {return mMyappPane;}
    private final MyappHelpMenu mHelpMenu;
    public MyappHelpMenu getHelpMenu() {return mHelpMenu;}

// constructors -----------------------------------------------------------------------------
    public myappMenuBar(MyappPane pMyappPane) {
        mMyappPane = pMyappPane;
        setUseSystemMenuBar(true);
        mHelpMenu = new MyappHelpMenu(pMyappPane);
        getMenus().add(mHelpMenu);
    }
}

回答1:


The problem was caused by the splash screen (java -splash:../img.png), as it is an AWT feature and not a JavaFX feature , nothing seems to help combine the AWT and JavaFX threads together in a single thread and -Djavafx.embed.singleThread=true doesn't seem to work.

For now I just disabled the splash screen and I plan to implement it as a JavaFX Pane from within the app.



来源:https://stackoverflow.com/questions/42157377/osx-system-menubar-not-working-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!