简体   繁体   English

将图标添加到jar文件的功能

[英]The ability to add an icon to a jar file

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: 我一直在寻找如何更改可执行jar文件的默认Java“咖啡杯”图标,并且发现该方法是:

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 . 我不知道如何将其添加到我的JavaFx类中 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);
    }
}

If you want to change the icon of your file, you could try this tutorial http://code.makery.ch/java/javafx-8-tutorial-part7/ 如果要更改文件图标,可以尝试使用本教程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 . 如果你有> = 7u10运行,你也可以试试这个(这是相当短的):添加一个<fx:icon >元素,像它的解释这里

<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) 如果您运行的是7u9或更低版本,则可以按照本文并回答以实现您的目标: 在独立的JavaFX应用程序(.exe)中包含一个图标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM