0

I'm working on a game with a small team and they've opened a ticket to change the IconImage, which takes in an ImageIcon object.

I create an ImageIcon object with a java.net.URL pointing to the file location in the CLASSPATH. Then I create an Image object out of ImageIcon.getImage().

Later on in the program, I pass the Image object mentioned above to jframe.setIconImage();

If I run the program in debug, I can see the path to the image is correct, reflecting it's place in the CLASSPATH, but the icon doesn't change. If I step into jframe.setIconImage(), I get to a point where JFrame.java is calling JFrame.super.setIconImage(), but the value of image being passed to the super class is "" (empty string).

I have code in the main class, src folder structure, out/bin folder structure, and a picture of the value being passed as empty string.

Any advise at all is much appreciated and thanks in advance for your time.

==Code==

package orsc;

import orsc.Config;

import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.io.File;

public class ORSCFrame extends ORSCApplet {

    private static final long serialVersionUID = 1L;

    public String getCacheLocation() {
        return Config.F_CACHE_DIR + File.separator;
    }

    public static void main(String[] args) {
        JFrame jframe = new JFrame(Config.SERVER_NAME);
        ImageIcon orscIcon = new ImageIcon(ORSCFrame.class.getResource("icon.png"));
        Image orscIconImage = orscIcon.getImage();

        final Applet applet = new ORSCFrame();
        applet.setPreferredSize(new Dimension(512, 334 + 12));
        jframe.getContentPane().setLayout(new BorderLayout());
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jframe.getContentPane().add(applet);
        jframe.setResizable(true);
        jframe.setVisible(true);
//      jframe.setAlwaysOnTop(true);
        jframe.setBackground(Color.black);
        jframe.setMinimumSize(new Dimension(512, 334 + 12));
        jframe.setIconImage(orscIconImage);
        jframe.pack();
        jframe.setLocationRelativeTo(null);

        applet.init();
        applet.start();
//      jframe.add(applet);
    }

    @Override
    public void playSound(byte[] soundData, int offset, int dataLength) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void stopSoundPlayer() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    } 
}

== src folder ==

enter image description here

==out/bin folder ==

enter image description here

==step into line 33 (jframe.setIconImage(orscIconImage);) ==

enter image description here

==pic of jframe ==

enter image description here

  • I would suggest that the issue has more to do with what you IDE's debugger is doing then Java. Use ` System.out.println` statement to test the state of the variables instead, if your still not sure – MadProgrammer Dec 13 '18 at 02:19
  • You're also better off using [`Window#setIconImages(List)`](https://docs.oracle.com/javase/10/docs/api/java/awt/Window.html#setIconImages(java.util.List)) instead, as it will better support multiple resolutions – MadProgrammer Dec 13 '18 at 02:21
  • 1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). E.G. [This answer](https://stackoverflow.com/a/10862262/418556) hot links to an image embedded in [this question](https://stackoverflow.com/q/10861852/418556). – Andrew Thompson Dec 13 '18 at 02:58

0 Answers0