0

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);
    }
}
josephino
  • 360
  • 4
  • 21
  • 1
    Is there a reason to use the external library? Doesn't using a regular JavaFX `MenuBar` and calling [`setUseSystemMenuBar(true)`](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/MenuBar.html#setUseSystemMenuBar-boolean-) work? – James_D Feb 10 '17 at 13:11
  • @James_D actually it doesn't, "setUseSystemMenuBar(true)" has no effect. – josephino Feb 10 '17 at 13:57
  • It works fine for me. If it's not working, you're probably doing something wrong... post some code. – James_D Feb 10 '17 at 14:15
  • I took a look at the library you linked. It uses non-public API classes all over the place, and consequently it can't be robust with respect to different JDK versions, etc. That's probably why it's failing (though there may be other reasons too). I would just use the standard API way of achieving this. – James_D Feb 10 '17 at 16:12
  • Thanks @James_D , I added the MyAppMenuBar class code, I use that class to construct the menuBar and then I instantiated it and use it later. – josephino Feb 10 '17 at 17:49

1 Answers1

2

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.

josephino
  • 360
  • 4
  • 21
  • It seems that the system menu bar does not work indeed in Javafx Version: 8.0.241-b07, Runtime Version: 1.8.0_251-b08 in OSX 10.15.6. There is no response in the menu bar when clicked on with the mouse. – Dezzo Jul 20 '20 at 16:34