简体   繁体   中英

My icon image doesnt show up in JFrame on mac

My image for logo doesnt show up on mac. there is no java logo in Jframe to begin with? what am I missing?

package test;

import javax.swing.*;

public class Demo {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setTitle("this is the frame title");
        frame.setSize(420,420);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setVisible(true);
        
        ImageIcon image = new ImageIcon("logo.png");
        frame.setIconImage(image.getImage());
    }       
}

在此处输入图像描述

the mac OS will not show your icon, there's nothing wrong with your code, what you can do is enable the look and feel for cross platform. here at the docs you can see how achieve this and configure it. Basically before start your jframe do this:

UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName();
// you can even set a theme on it
MetalLookAndFeel.setCurrentTheme(new OceanTheme()); // since Metal is the L&F for cross platforms.
JFrame.setDefaultLookAndFeelDecorated(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM