How can I change a java desktop application icon in Eclipse?

2

Is it possible to change the icon of a java desktop application in eclipse instead of having the default icon?

    
asked by anonymous 07.05.2015 / 19:10

1 answer

3

The problem with getting the icon to change is that your Java desktop application generates a .jar , and unlike files with extension .exe .jar does not have its own icon, its icon is the same for all .jar system, so you can not change the icon of it in the same way it does with .exe .

The solution I suggest is to create a shortcut and set the shortcut icon, .jar you hide in a system folder, and hope that the user never solves it.

Now, if you refer to the window icon and taskbar, you can change it like this:

frame.setIconImage(Toolkit.getDefaultToolkit().getImage("img\logo.jpg"));

For example:

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class JanelaComIcone extends JFrame {
    private static final long serialVersionUID = 1L;
    private JPanel contentPane;
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    JanelaComIcone frame = new JanelaComIcone();
                    frame.setVisible(true);
                    frame.setIconImage(Toolkit.getDefaultToolkit().getImage("img\logo.jpg"));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public JanelaComIcone() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);
    }
}

The img folder you put in the root of the project.

    
07.05.2015 / 20:09