相关疑难解决方法(0)

用于JavaFX应用程序的ICON设置在Windows中可见,但在Ubuntu中不可见

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

我正在设置JavaFX应用程序ICON,它在Windows系统上非常清晰可见,但在Ubuntu上却没有.

在Windows上:

在任务栏上 在窗口

在Ubuntu上:

在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();
    }
}
Run Code Online (Sandbox Code Playgroud)

ubuntu icons javafx-8

13
推荐指数
1
解决办法
2052
查看次数

在JavaFX中设置舞台上的图标

我想知道如何在javaFX舞台上设置图标.我找到了这种方法,但它没有正常工作.

  stage.getIcons().add(new Image(iconImagePath));
Run Code Online (Sandbox Code Playgroud)

stage是javafx.stage.Stage的一个实例,我导入了javafx.scene.image.Image.这是我们收到的例外情况:

网址无效:找不到无效的网址或资源

此外,iconImagePath没有任何问题,它的值是"G:/test.jpg",并且G驱动器中有一个名为test的jpg文件.此外,当我们使用ImageIO读取相同的URL时,我们可以轻松完成.

java javafx stagewebview

9
推荐指数
2
解决办法
3万
查看次数

标签 统计

icons ×1

java ×1

javafx ×1

javafx-8 ×1

stagewebview ×1

ubuntu ×1