Jump to content

Java Swing Icon Help

Go to solution Solved by fizzlesticks,
public class B extends JFrame{
    public B(){
        Toolkit tk = Toolkit.getDefaultToolkit();
        Image icon = tk.getImage(getClass().getResource("myicon.png"));
        setIconImage(icon);
        setSize(new Dimension(400,400));
        setVisible(true);
    }

    public static void main(String...args) {
        B b = new B();
    }
}

Use a toolkit to load the image and get the path inside the jar file by using getResource(). This will look in the root of the jar. If you have a resources folder or something you can change it to getResource("somefolder/whatever/myicon.png");

I need some help, I've been going all over the internet looking for some help but to no avail. What I am trying to do is to get an icon I made to be the icon of the window. Like the image that sit's in the upper left hand corner of the window. I've tried Eclipse's way but that makes an absolute, I plan on having this icon in the jar file and is loaded directly from the jar file.

Brah, do you even Java?

Link to comment
Share on other sites

Link to post
Share on other sites

public class B extends JFrame{
    public B(){
        Toolkit tk = Toolkit.getDefaultToolkit();
        Image icon = tk.getImage(getClass().getResource("myicon.png"));
        setIconImage(icon);
        setSize(new Dimension(400,400));
        setVisible(true);
    }

    public static void main(String...args) {
        B b = new B();
    }
}

Use a toolkit to load the image and get the path inside the jar file by using getResource(). This will look in the root of the jar. If you have a resources folder or something you can change it to getResource("somefolder/whatever/myicon.png");

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, fizzlesticks said:

public class B extends JFrame{
    public B(){
        Toolkit tk = Toolkit.getDefaultToolkit();
        Image icon = tk.getImage(getClass().getResource("myicon.png"));
        setIconImage(icon);
        setSize(new Dimension(400,400));
        setVisible(true);
    }

    public static void main(String...args) {
        B b = new B();
    }
}

Use a toolkit to load the image and get the path inside the jar file by using getResource(). This will look in the root of the jar. If you have a resources folder or something you can change it to getResource("somefolder/whatever/myicon.png");

Thanks, sorry if it was a noob question.

Brah, do you even Java?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×