How do I change the default application icon in Java?

后端 未结 10 765
心在旅途
心在旅途 2020-11-27 17:02

I\'m using NetBeans, trying to change the familiar Java coffee cup icon to a png file that I have saved in a resources directory in the jar file. I\'ve found many different

相关标签:
10条回答
  • 2020-11-27 17:32
    java.net.URL url = ClassLoader.getSystemResource("com/xyz/resources/camera.png");
    

    May or may not require a '/' at the front of the path.

    0 讨论(0)
  • 2020-11-27 17:33

    In a class that extends a javax.swing.JFrame use method setIconImage.

    this.setIconImage(new ImageIcon(getClass().getResource("/resource/icon.png")).getImage());
    
    0 讨论(0)
  • 2020-11-27 17:35

    Example:

    URL imageURL = this.getClass().getClassLoader().getResource("Gui/icon/report-go-icon.png");
    ImageIcon iChing = new ImageIcon("C:\\Users\\RrezartP\\Documents\\NetBeansProjects\\Inventari\\src\\Gui\\icon\\report-go-icon.png");      
    btnReport.setIcon(iChing); 
    System.out.println(imageURL);
    
    0 讨论(0)
  • 2020-11-27 17:38

    inside frame constructor

    try{    
           setIconImage(ImageIO.read(new File("./images/icon.png")));   
       }
    catch (Exception ex){
           //do something
       }
    
    0 讨论(0)
提交回复
热议问题