There are applications in Java . In the application, an icon is generated and placed next to the application in the res folder (the icon name is always the same tray.png — that is, it is overwritten ). So when the application starts, it already has some kind of icon (for example, a black one ). This image is loaded and installed , then a new icon is generated (for example, green ), and set again to the icon, respectively, the icon should be replaced from black to green , but this does not happen (the icon is updated, but again to black, which is no longer in the resources basically).

I save the icons as follows:

ImageWriteEx ImageWriteEx = new ImageWriteEx(); BufferedImage bi = ImageWriteEx.createImageWithText(); File outputfile = new File("./res/tray.png"); ImageIO.write(bi, "png", outputfile); 

I load the icons like this:

 Image image = Toolkit.getDefaultToolkit().getImage("./res/tray.png"); setIconImage(image); 

So, what's my problem?

    1 answer 1

    I would suggest first uploading the image as a resource using getResource or getResourceAsStream :

     // this здесь добавлен исключительно для наглядности this.getClass().getResource("res/tray.png") 

    And then look for a method that takes a picture as an InputStream or ImageInputStream

    • Unfortunately, through getResource () I do not put a picture at all, but I got out of position like this: without saving any resources, I pass directly the variable bi - Flaber
    • It is even better if the icon was saved in order to be read. - ppopoff