Tobias L. February 2016

Set application icon for FileChooser in javaFX

After I start a FileChooser window in my javaFX application in windows the application icon in the taskbar shows a java icon and not the icon of the main window. Is there a possibility to select an application icon for a FileChooser instance?

Thanks for your answeres!

Answers


RAnders00 February 2016

It is possible to do so, but apparently only when you have a visible parent stage.

Provided that stage in the following example is visible, you can do this:

stage.getIcons().add(new Image("http://i.imgur.com/1M3UaZy.png"));
FileChooser fileChooser = new FileChooser();
File result = fileChooser.showSaveDialog(stage);

This opens the file chooser as a child of the given stage, which has the given icon.

I stepped through the JavaFX source code with a debugger (Oracle Java 8u72 on Windows x64), and there is not single point in the Java code where the icon could be set. The parent window handle is passed into a native method, where it then the icon probably gets resolved somewhere in the Win32 windowing code.

Post Status

Asked in February 2016
Viewed 2,588 times
Voted 8
Answered 1 times

Search




Leave an answer