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");
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 accountSign in
Already have an account? Sign in here.
Sign In Now