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?

0 comment threads