这有点奇怪,或者我的代码有问题。
我正在设置 JavaFX 应用程序图标,它在 Windows 系统上非常明显,但在 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 问题跟踪器中的一个未解决问题。
Gtk: Implement global system menu bar support
根据 JavaFX 开发人员对 similar issue 的评论:
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 问题与 JDK 问题合并之前,RT-28202 是上述链接问题的问题 ID。
这个问题的票数非常少,因此没有引起太大兴趣。如果您已注册为贡献者,请随时为该问题投票。
关于ubuntu - 为 JavaFX 应用程序设置的图标在 Windows 中可见,但在 Ubuntu 中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26039593/