這有點奇怪,或者可能是我的代碼有問題。爲JavaFX應用程序設置的ICON在Windows中可見,但在Ubuntu中不可見
我正在設置JavaFX應用程序ICON,它在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();
}
}
[只是調整您的圖標在不同的大小,他們都在這裏回答](http://stackoverflow.com/questions/27017031/javafx-2-window-icon-not-working)[這裏是標準大小](http://www.visualpharm.com/articles/icon_sizes.html)希望這可以幫助:) – 2015-01-10 09:55:25