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.

Comments on Setting icon with javaFX does not show in task list

Post

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

2 comment threads

Wayland and window icons (3 comments)
Enter this command in a terminal: `file /home/watchmaker/playground/I48.png` It should print `PNG i... (1 comment)
Wayland and window icons
VGR‭ wrote 3 months ago · edited 2 months ago

I have found that Wayland no longer pays attention to the _NET_WM_ICON X property on windows (the standard way for decades of assigning an icon to a window). Instead, it reads the window’s WM_CLASS property, and assumes a window’s icon is defined in the $XDG_HOME/applications/\$WM_CLASS.desktop file (XDG_HOME defaults to $HOME/.local/share). The Icon= line in that file is resolved against the $XDG_DATA_HOME/icons directory.

(It is possible that all directories in $XDG_DATA_DIRS are used, as described in https://specifications.freedesktop.org/basedir/latest/#variables. I have never found any official documentation on this behavior.)

System‭ wrote 2 months ago

Thread renamed from "Are you using Gnome? I have found that Gnome no longer pays attention to the NETWMICON X property on..." to "Are you using Wayland? I have found that Wayland no longer pays attention to the NETWMICON X property on..." by VGR‭

System‭ wrote 2 months ago

Thread renamed from "Are you using Wayland? I have found that Wayland no longer pays attention to the NETWMICON X property on..." to "Wayland and window icons" by VGR‭