java fx 内置图标,如何在我的应用程序的java fx 2.0中更改舞台标题栏上的图标

I have tried the

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

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

Please help. Thanks in advance.

解决方案

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);

}

}

Output Screnshot

zLPre.png

Updated for JavaFX 8

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"));

INVvn.png

Hope it helps. Thanks!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值