0

I've been looking around on how to change the default Java "coffee cup" icon of the executable jar file and the way to do it, I've found, is:

getFrame().setIconImage(Toolkit.getDefaultToolkit().getImage(getClass()
.getClassLoader().getResource("MyProject/resources/myIcon.png")));

OR:

this.getFrame().setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("plagialyzer/resources/PlagiaLyzerIcon.png")));

I can't figure out how to add this into my JavaFx classes. Could anyone please point me on how to add this to, for example, the class below:

public class WakiliProject extends Application {

    private double xOffset = 0;
    private double yOffset = 0;

    @Override
    public void start(final Stage primaryStage) {

        ScreensController mainContainer = new ScreensController();

        Group root = new Group();

        root.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                xOffset = event.getSceneX();
                yOffset = event.getSceneY();
            }
        });

        root.setOnMouseDragged(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                primaryStage.setX(event.getScreenX() - xOffset);
                primaryStage.setY(event.getScreenY() - yOffset);
            }
        });

        root.getChildren().addAll(mainContainer);
        Scene scene = new Scene(root, 900, 624);
        primaryStage.setScene(scene);

        primaryStage.initStyle(StageStyle.UNDECORATED);
        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.getIcons().add(new Image("/MediaTools/antibanner.png"));
        primaryStage.setTitle("Wakili");

        primaryStage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}
ILikeProgramming
  • 293
  • 3
  • 8
  • 23

1 Answers1

0

If you want to change the icon of your file, you could try this tutorial http://code.makery.ch/java/javafx-8-tutorial-part7/

If you have >= 7u10 running, you could also try this (it's rather short): Adding an <fx:icon > element, like it's explained here.

<fx:deploy ...> 
     <fx:info> 
         <fx:icon href="default.png"/> 
     </fx:info> 
     ... 
</fx:deploy>

In case you are running 7u9 or lower, you can follow this post and answer to achieve your goal: including an icon into a self-contained JavaFX application (.exe)

Community
  • 1
  • 1
XWaveX
  • 268
  • 2
  • 11