2

在研究了相当多的帖子并尝试了所有内容之后,我无法自己完成一项简单的任务,比如使用 eclipse IDE 和 Java FX 2 在标题栏上设置一个图标。

它要么带有默认的空窗口图标,要么返回黑色。请让我知道我做错了什么。

以下是我的一些尝试,

//Image ico = new Image(UI.class.getResourceAsStream("Sunset.jpg"), 16, 16,      true,true);        
//Image ico = new Image("Sunset.jpg", true);// looks inside src folder
//primaryStage.getIcons().add(new Image(UI.class.getResourceAsStream("/title.jpeg")));
//primaryStage.getIcons().add(new Image(UI.class.getResourceAsStream("title.jpeg")));

Image ico = new Image(UI.class.getResourceAsStream("Sunset.jpg"));
primaryStage.getIcons().add(ico);       

我用我一直在使用的图片尝试了以下方法,

  1. 我使用属性为 300x300 像素的图片
  2. 我将 300x300 像素的图片转换为 16x16 像素
  3. 我使用 *.ico 和 32x32 和 16x16 像素
  4. 我将 .ico 转换为 jpeg 并尝试过。

请让我知道,我该如何克服这个问题。谢谢 !

系统详情:

java.runtime.version - 1.7.0_11-b21
javafx.runtime.version - 2.2.4-b19
操作系统名称 - MS Win XP Professional
操作系统版本 - 5.1.2600 Service Pack 3 Build 2600
操作系统架构 - 32 位
显卡 - Intel® HD Graphics
显卡驱动程序 – igxpmp32.sys 版本 6.14.10.5384

4

3 回答 3

3

原因似乎是 JavaFx 中的一个潜在错误。如果您将系统设置为低于 32 位的颜色,您的任务栏和标题栏图标会出现黑框。将您的系统设置为 32 位颜色将修复它。

于 2013-05-10T17:49:14.543 回答
1

以下对我有用:

Image image = new Image(<some valid image location here>);
stage.getIcons().setAll(image);

这是一个示例应用程序:

import static javafx.application.Application.launch;
import javafx.application.*;
import javafx.scene.Scene;
import javafx.scene.image.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class IconApp extends Application {
  @Override public void start(Stage stage) {
    Image image = new Image(
      "http://icons.iconarchive.com/icons/tooschee/misc/128/Present-icon.png"
    );
    stage.getIcons().setAll(image);

    final VBox layout = new VBox(10);
    layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
    layout.getChildren().setAll(new ImageView(image));

    stage.setScene(new Scene(layout));
    stage.show();
  }

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

// icon license (creative commons 3 with attribution): 
//   http://creativecommons.org/licenses/by-nc/3.0/
// icon attribution: 
//   http://tooschee.com/portfolio?worksCategory=icons

以及应用程序的输出(您可以在标题栏的左上角看到舞台图标):

礼物图标

该图标还显示在操作系统任务栏中:

presenticonintaskbar

测试系统为 Windows 7、Java 8b77。

于 2013-03-07T22:52:27.720 回答
0

如果您将显示器置于 16 位操作模式,即使在 Windows 7 上也可以重现此错误:屏幕分辨率 -> 高级设置 -> 显示器(选项卡)-> 颜色 = 16 位

似乎问题已在此处填写到 JavaFX 跟踪器中: https ://javafx-jira.kenai.com/browse/RT-28947由 Joe S. 来自另一个答案,但我不会打赌它已修复JDK8.

于 2015-02-17T13:20:50.823 回答