Image

Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Setting icon with javaFX does not show in task list

+1
−0

I try to set an icon (*.png) with javaFX, but it does not show in the task bar, instead I see the default icon (white cogwheel on light gray background).

Here is my code:

package application;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

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

// copied and adapted from https://codemia.io/knowledge-hub/path/javafx_application_icon
//
// java -version
// openjdk version "21.0.8" 2025-07-15
// OpenJDK Runtime Environment (build 21.0.8+9-Ubuntu-0ubuntu124.04.1)
// OpenJDK 64-Bit Server VM (build 21.0.8+9-Ubuntu-0ubuntu124.04.1, mixed mode, sharing)
//
// lsb_release -a
// No LSB modules are available.
// Distributor ID:	Ubuntu
// Description:	Ubuntu 24.04.3 LTS
// Release:	24.04
// Codename:	noble

public class IconTest extends Application {

	// manually checked that the file can be displayed and the image has 48x48 pixels
	String pathname = "/home/watchmaker/playground/I48.png";

	@Override
	public void start(Stage stage) throws FileNotFoundException {
		// Create a layout
		StackPane root = new StackPane();
		Scene scene = new Scene(root, 400, 300);

		File ifi = new File(pathname);
		// just in case something's wrong at runtime
		System.out.println("File=" + ifi.getAbsolutePath() + " is readable=" + ifi.canRead());
		Image icon = new Image(new FileInputStream(ifi));
		stage.getIcons().add(icon);

		stage.setTitle("Try and cry");
		stage.setScene(scene);
		stage.show();
	}

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

What is wrong?

History

0 comment threads

Sign up to answer this question »