(Solved) Got confused with setIcons()

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import static java.lang.Math.abs;
import javax.imageio.ImageIO;       

 try {
            cfg.setIcons( new BufferedImage[]{
                ImageIO.read(new File("/Textures/g1616.png")),
                ImageIO.read(new File("/Textures/g1632.png"))
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        app.setDisplayStatView(false);  //  hide statistics

I’m trying to change the display ICON. Problem is , It just doesn’t work, nothing is changed.
running system win10 64.
did i use right importing? (java.awt.image.BufferedImage and javax.imageio.ImageIO)
can anyone tell me what to do ?

1 Like

Oh, dears:
Just got it works.

I copied png files to d:/ and change code to ImageIO.read(new File(d://g1632.png")) then it works.
But why it can’t read ( “/Textures/g1632.png”) ? it is in the asset directory.

It should work.

When you write

AssetKey key = new AssetKey("/Textures/g1616.png");

you are using the asset manager to access the PNG.

When you write

new File("/Textures/g1616.png");

you are using an absolute path in the local filesystem to access the PNG.

These are two very different mechanisms. While the asset manager can be configured to use the local filesystem, by default it uses the classpath. For typical projects, selected files in the project’s “assets” subdirectory are incorporated into the classpath so that they’re available no matter what computer the application is running on.

The IDE executes applications in the project directory, so as long as you’re in the IDE, something like this should work:

new File("./assets/Textures/g1616.png");

but this is likely to break if you run the application outside the IDE: in a different working directory, or an a different computer.

For portability, you probably want to access those PNG files as assets on the classpath, using the asset manager.

Does that help?

1 Like

I just copied code from tutorial example.
It seems like I should spend more time getting though JME3.
Thank you sgold.

1 Like