如何在我的应用程序的java fx 2.0中更改舞台标题栏上的图标 [英] How to Change the icon on the title bar of a stage in java fx 2.0 of my application

查看:199
本文介绍了如何在我的应用程序的java fx 2.0中更改舞台标题栏上的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了

 stage.getIcons().add(new Image("attuncore.jpg")); 

但我不知道出了什么问题..

But I don't know what is going wrong ..

请帮忙。在此先感谢。

推荐答案

初学者的完整程序:)此程序设置Stack Overflow Icon。

Full program for starters :) This program set Stack Overflow Icon.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class StackoverflowIcon extends Application {

    @Override
    public void start(Stage stage) {
        StackPane root = new StackPane();
        // set icon
        stage.getIcons().add(new Image("/path/to/stackoverflow.jpg"));
        stage.setTitle("Wow!! Stackoverflow Icon");
        stage.setScene(new Scene(root, 300, 250));
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

输出Screnshot


更新为JavaFX 8

Updated for JavaFX 8

无需更改代码。它仍然可以正常工作。在Java 1.8(1.8.0_45)中经过测试和验证。路径可以设置为本地或远程都支持。

No need to change the code. It still works fine. Tested and verified in Java 1.8(1.8.0_45). Path can be set to local or remote both are supported.

stage.getIcons().add(new Image("/path/to/javaicon.png"));

OR

stage.getIcons().add(new Image("https://example.com/javaicon.png"));

希望它有所帮助。谢谢!!

Hope it helps. Thanks!!

这篇关于如何在我的应用程序的java fx 2.0中更改舞台标题栏上的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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