0

I'm currently making an application in JavaSwing as a project for my class in an Uni. Would you mind helping me with the given problem? I can't find the needed solution and

frameUI.setIconImage(frame.getIcon());

is not really what I need..

Example

In the frame class (only related to icon):

    private Image icon;
    private String iconPath = ICON_PATH;

    // Constructor
    public Frame() {
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();

        initIcon(kit);
    }

    // Set frame icon
    private void initIcon(@NotNull Toolkit kit) {
        icon = kit.getImage(iconPath);
    }

    public Image getIcon() {
        return icon;
    }

    public void setIcon(Image icon) {
        this.icon = icon;
    }

    public String getIconPath() {
        return iconPath;
    }

    public void setIconPath(String iconPath) {
        this.iconPath = iconPath;
    }

In the FrameAction class:

    public FrameAction() {
        frame = new Frame();
        frameUI = new FrameUI();
        initView();

    }

    private void initView() {
        // Setting the initial frame icon
        frameUI.setIconImage(frame.getIcon());
    }

FrameUI extends JFrame

Ilija Ivic
  • 107
  • 2
  • 9
  • I'm almost positive that setting the image of the app's icon in the tray is operating specific, meaning that it's different for Mac, Windows, Ubuntu, etc. You will need to research how to set the image of tray icons on Mac, possibly for the specific version of Mac you're using if it has changed between versions. I don't believe the Swing framework has this functionality. – Jonny Henly Oct 12 '20 at 17:57
  • Actually there might be a Stack Overflow question and answer that addresses your question: [How do I put a Java app in the system tray?](https://stackoverflow.com/questions/758083/how-do-i-put-a-java-app-in-the-system-tray) – Jonny Henly Oct 12 '20 at 18:01
  • The `setIconImage(...)` method works fine for me on Windows. Don't know if it different on a Mac. Pot your [mre] demonstrating the problem. – camickr Oct 12 '20 at 18:51
  • `if (new java.io.File(imagePath).exists()) { jFrame1.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(imagePath)); }` – DevilsHnd - 退職した Oct 12 '20 at 22:08

0 Answers0