0

I have a program that I made for my Spanish teacher and I want to make the dock/taskbar have an icon. I have an attempt here, but it doesn't work.

package com.jaketherey;

import java.awt.Color;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Inglés_Switcher {

public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

        JFrame frame = new switcherContent();

        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(950, 850);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setTitle("Inglés Switcher by Jacob Batista");
        frame.getContentPane().setBackground(Color.GREEN);

        //Attempt to Add Icon, Remember I want it for both Mac and Windows

        ImageIcon icon = new ImageIcon("/com/jaketherey/ñ.png");
        frame.setIconImage(icon.getImage());

        }

    });

}

}

If you need the JFrame it uses for the content then I will give it to you but I didn't think it was important for the problem...

Help? Thanks.

Jacob B.
  • 423
  • 3
  • 12

1 Answers1

2

For Windows, start by taking a look at Window#setIconImages, demonstrated here

For MacOS, it becomes a little more difficult. You need to make use of a custom library (available only on the Mac)

Apple eAWT provides the Application class that allows to change the dock icon of an application.

import com.apple.eawt.Application;
...
Application application = Application.getApplication();
Image image = ...
application.setDockIconImage(image);

Also demonstrated here

As stated in the example linked above, the preferred method for depleying on MacOS would be to make use of the Mac OS application bundler

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366