Reputation: 269
After researching quite a bit of the posts and trying everything out, I am out of options on my own to do a task as simple as setting an icon on the title bar using eclipse IDE and Java FX 2.
It either comes up with the default empty window icon or comes back black. Please let me know what I am doing wrong.
Here are some of my attempts,
//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);
I have tried the following with the pictures I have been using,
Please let me know, how I can overcome this. Thanks !
System details:
java.runtime.version - 1.7.0_11-b21
javafx.runtime.version - 2.2.4-b19
OS Name - MS Win XP Professional
OS Version - 5.1.2600 Service Pack 3 Build 2600
OS architecture - 32 bit
Graphics card - Intel® HD Graphics
Graphics card driver – igxpmp32.sys Version 6.14.10.5384
Upvotes: 2
Views: 1848
Reputation: 327
This bug can be reproduced even on Windows 7 if you put the monitor in the 16 bit operating mode: Screen Resolution -> Advanced Settings -> Monitor (tab) -> Colors = 16 bit
Seems like the issue has been filled into the JavaFX tracker here: https://javafx-jira.kenai.com/browse/RT-28947 by Joe S. from the other answer, but I won't bet on having it fixed in JDK8.
Upvotes: 0
Reputation: 31
The cause seems to be a potential bug in JavaFx. If you have your system set to anything below 32-bit color you will get black boxes for your taskbar and title bar icons. Setting your system to 32-bit color will fix it.
Upvotes: 3
Reputation: 159341
The following works for me:
Image image = new Image(<some valid image location here>);
stage.getIcons().setAll(image);
Here is a sample app:
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
And the output of the app (you can see the stage icon in the top left corner of the title bar):
The icon also shows up in the operating system task bar:
Test system was Windows 7, Java 8b77.
Upvotes: 1