Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Desktop Icon for Java Application

I wish to thank you in advance for taking the time to read my question, and I would greatly appreciate any comments, answers, insights, techniques and critiques that you may be able to provide.

I'm looking for a useful method for changing the desktop icon for a Java application. I've looked into this for a few days now, but am not finding an accurate result.

Before you mark this down and call it a duplicate, I have read: How do I change the default application icon in Java? to others who asked this question), but this does not address my specific problem. I know that their method utilizes a url location instead of an import, but I am trying to learn how to use this with the import(if that is, in fact, possible). When I attempt to use their method for changing by source location. Besides that, the url example doesn't seem to work for a file stored on the computer. I get an "uncaught error" message when I attempt to run it.

I use the following format to declare an image that I have imported into NetBeans:

Image image = new ImageIcon("imported.png").getImage();
frame.setIconImage(image);

Now this works fine for the icon that displays in the toolbar and it also appears in the upper left-hand corner of the frame, but I still have the Java coffee-cup as the icon for the application when I clean and build it.

For additional resources to the code that I am using to attempt this:

import java.awt.Image;
import javax.swing.*;

public class Check {
    JFrame frame;
    public static void main(String[] args) {
        new Check().go();
    }
    private void go() {
        frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Image image = new ImageIcon("owl.gif").getImage();

        frame.setIconImage(image);
        frame.setVisible(true);
        frame.setSize(300, 300);
    }
}

The "owl.gif" bit is what I imported into NetBeans by click and drag method (as described in one of the books that I read that focused on NetBeans).

I'm looking for a way to make a file that I already have saved on my computer the desktop icon for my application after it is built.

like image 472
Jeremy Johnson Avatar asked Aug 11 '13 15:08

Jeremy Johnson


People also ask

How do I change the Java Swing app Icon?

How to change TitleBar icon in Java AWT and Swing. The setIconImage() method of Frame class is used to change the icon of Frame or Window. It changes the icon which is displayed at the left side of Frame or Window. The Toolkit class is used to get instance of Image class in AWT and Swing.

How do I get the Java Icon?

Click on the Start button and then click on the Control Panel option. In the Control Panel Search enter Java Control Panel. Click on the Java icon to open the Java Control Panel.

How do I change the JFrame Icon in Netbeans?

Setting the icon directly: JFrame. setIconImage("org/icon. png");

Is Java a desktop application?

As mentioned, Java can be used to create desktop applications. These applications can have attractive interfaces and designs, they can store and retrieve data from a database, and much more. For desktop application development, you can use Java Frameworks to build Graphical User Interfaces (GUI).


1 Answers

For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start1. JWS works on Windows, OS X & *nix.

  1. JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

The 'desktop integration' will use the image identified in the launch file as the desktop or menu item icon.

like image 107
Andrew Thompson Avatar answered Sep 27 '22 16:09

Andrew Thompson