OSX系统菜单栏不能在JavaFX中工作 [英] OSX System menubar not working in JavaFX

查看:128
本文介绍了OSX系统菜单栏不能在JavaFX中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从 https:/中使用 NSMenuFX /github.com/codecentric/NSMenuFX 使JavaFX应用程序使用MacOS系统菜单栏,但由于此方法返回始终 false ,它无法正常工作。

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()

该方法来自包: com.sun.javafx.tk.Toolkit

深入研究代码我发现 Toolkit.getToolkit()。getSystemMenu()。isSupported()调用方法来自 com.sun.glass.ui.Application ,它也总是返回false。

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();
}

此代码有什么问题,我怎样才能使用JavaFX app系统菜单栏。

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

注意:在OSX 10.12.3上使用的JDK为8u121。

NB :Used JDK is 8u121 on OSX 10.12.3.

编辑1:As在评论中建议,这里是一些代码。

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);
    }
}


推荐答案

问题是由启动画面(java -splash:../ img.png)引起的,因为它是一个AWT功能而不是 JavaFX 功能,似乎没有任何帮助组合单个线程中的 AWT 和JavaFX线程以及 -Djavafx.embed.singleThread = true 似乎没有工作。

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.

现在我只是禁用了启动画面,我计划在应用程序中将其作为JavaFX窗格实现。

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

这篇关于OSX系统菜单栏不能在JavaFX中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆