JavaFX Application Icon
Assuming your stage is "stage" and the file is on the filesystem:
stage.getIcons().add(new Image("file:icon.png"));
As per the comment below, if it's wrapped in a containing jar you'll need to use the following approach instead:
stage.getIcons().add(new Image(<yourclassname>.class.getResourceAsStream("icon.png")));
Full program for starters :) This program sets icon for StackOverflowIcon.
import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.image.Image;import javafx.scene.layout.StackPane;import javafx.stage.Stage;public class StackoverflowIcon extends Application { @Override public void start(Stage stage) { StackPane root = new StackPane(); // set icon stage.getIcons().add(new Image("/path/to/stackoverflow.jpg")); stage.setTitle("Wow!! Stackoverflow Icon"); stage.setScene(new Scene(root, 300, 250)); stage.show(); } public static void main(String[] args) { launch(args); }}
Output Screnshot
Updated for JavaFX 8
No need to change the code. It still works fine. Tested and verified in Java 1.8(1.8.0_45). Path can be set to local or remote both are supported.
stage.getIcons().add(new Image("/path/to/javaicon.png"));
OR
stage.getIcons().add(new Image("https://example.com/javaicon.png"));
Hope it helps. Thanks!!