用于JavaFX应用程序的ICON设置在Windows中可见,但在Ubuntu中不可见 [英] ICON set for JavaFX application is visible in Windows but not in Ubuntu

查看:283
本文介绍了用于JavaFX应用程序的ICON设置在Windows中可见,但在Ubuntu中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有点奇怪或者我的代码可能有问题。

It is a bit weird or maybe there is something wrong with my code.

我正在设置JavaFX应用程序ICON,这在Windows系统上非常明显但不在Ubuntu。

I am setting JavaFX application ICON which is very well visible on Windows system but not on Ubuntu.

在Windows上:


在Ubuntu上:

对此背后的原因有所了解。

代码示例:

@Override
public void start(Stage stage) throws Exception {

    try {
        setUserAgentStylesheet(STYLESHEET_MODENA);
        FXMLLoader loader = new FXMLLoader();
        Parent root = (Parent) loader.load(getClass().getResourceAsStream("ui/ParentWindow.fxml"));
        final ParentWindowController controller = (ParentWindowController) loader.getController();

        stage.addEventHandler(WindowEvent.WINDOW_SHOWN, controller::handleWindowShownEvent);
        stage.addEventHandler(WindowEvent.WINDOW_SHOWING, controller::handleWindowShowingEvent);
        stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, controller::handleWindowClosingRequestedEvent);

        Scene scene = new Scene(root);

        scene.getStylesheets().setAll(
                getClass().getResource("ui/css/ParentWindow.css").toExternalForm()
        );

        stage.setScene(scene);
        stage.initStyle(StageStyle.UNIFIED);
        stage.setResizable(false);
        stage.toFront();
        stage.setTitle("Simple JavaFX Tool");
        stage.getIcons().add(new Image(getClass().getResourceAsStream("resources/images/icon.jpg")));
        stage.show();
    } catch (IOException iOException) {
        iOException.printStackTrace();
    }
}


推荐答案

寻找解决方案的人,这是JDK问题跟踪器中的一个未解决的问题。

For people looking for solution, this is an open issue in the JDK issue tracker.

Gtk:实施全球系统菜单栏支持

根据JavaFX开发人员对类似问题

According to a comment by JavaFX developer on a similar issue :


Glass / FX目前不支持全局菜单栏在GTK(RT-28202)上。因此,Glass不会设置任何应用程序范围的提示来指定应用程序名称或应用程序图标。桌面环境必须自己猜测它们(可能使用窗口的标题和图标)。因此,应用程序窗口(上面的#1)应始终显示正确的标题是正确的,而其他3个位置可能会或可能不会根据时间显示正确的标题。在实施RT-28202之前,这不太可能改变。

Glass/FX currently doesn't support the global menu bar on GTK (RT-28202). As such, Glass doesn't set any application-wide hints to specify the application name or application icon. The desktop environment has to guess them itself (likely, using a window's title and icon). Hence, it is correct that the "app window" (#1 above) should always display the correct title, while the other 3 places may or may not display the correct title depending on timings. This is unlikely to change until RT-28202 is implemented.

在JavaFX问题出现之前,RT-28202是上述链接问题的问题ID与JDK问题合并。

RT-28202 was the issue id for the above linked issue before JavaFX issues was merged with JDK issues.

这个问题的选票非常少,因此没有引起太多兴趣。如果您已注册为撰稿人,请随时为该问题投票。

这篇关于用于JavaFX应用程序的ICON设置在Windows中可见,但在Ubuntu中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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