Java 我的图标图像不会在mac上的JFrame中显示
我的徽标图像没有显示在mac上。Jframe中没有java徽标吗? 我错过了什么Java 我的图标图像不会在mac上的JFrame中显示,java,Java,我的徽标图像没有显示在mac上。Jframe中没有java徽标吗? 我错过了什么 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");
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());
}
}
mac OS不会显示您的图标,您的代码没有问题,您可以做的是启用跨平台的外观。在文档中,您可以看到如何实现这一点并对其进行配置。基本上,在启动jframe之前,请执行以下操作:
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);
mac OS不会显示您的图标,您的代码没有问题,您可以做的是启用跨平台的外观。在文档中,您可以看到如何实现这一点并对其进行配置。基本上,在启动jframe之前,请执行以下操作:
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);
不要试图通过文件系统路径加载图像(即使它现在可以工作,在JAR中封装代码后也会遇到问题)。相反,尝试将它们作为项目资源加载。您可能想要读取,但不要尝试通过文件系统路径加载图像(即使它现在可以工作,在JAR中封装代码后也会遇到问题)。相反,尝试将它们作为项目资源加载。你可能想看看,