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

Asked

Viewed 4,413 times

2

You can change the icon of a java desktop application in eclipse instead of the default icon?

  • It is an Android or Desktop application?

  • It is a Desktop application

1 answer

3


The problem with being able to change the icon is why your Java Desktop application generates a .jar, and unlike files with extension .exe the .jar does not have its own icon, its icon is the same for all .jar system, so you can’t change its icon the way you do with the .exe.

The solution I suggest is to create a shortcut and set the shortcut icon, the .jar you leave it hidden in a system folder, and hope that the user never resolves to poke around in it.

Now, if you refer to the window and taskbar icon 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 briefcase img you put at the root of the project.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.