gpt4 book ai didi

java - setImageIcon 不在 mac swing 窗口上设置 JFrame 图标

转载 作者:行者123 更新时间:2023-12-01 07:06:13 26 4
gpt4 key购买 nike

我已经尝试过 Stack 中的大量代码。由于某种原因,它只是没有为我的 JFrame 设置 ImageIcon,注释是其他未成功的尝试;我避免调用 super,以便我可以引用 JFrame -- GUIPhotoAlbum extends JFrame;代码:

public GUIPhotoAlbum ()
{
super("PhotoAlbum");
ImageIcon img = new ImageIcon("Photos/albumIcon.png");
this.setIconImage(img.getImage());

/*
try{
setIconImage(ImageIO.read(new File("Photos/albumIcon.png")));
}catch(Exception e){
System.out.print("Didn't work.");
}
*/

setSize(875, 625);
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout(5, 5));

initComponents();
initMenuBar();

initTopPanel();
add(topPanel, BorderLayout.CENTER);

initBottomPanel();
add(bottomPanel, BorderLayout.SOUTH);

addListeners();

setLocationRelativeTo(null);
setVisible(true);
}

编辑我正在运行这样的程序,我尝试在 GUIPhotoAlbum() 构造函数中设置 JFrame 的 ImageIcon ;这是驱动程序:

public class AlbumDriver
{
public static void main (String [ ] args)
{
SwingUtilities.invokeLater
(
new Runnable()
{
@Override
public void run()
{
GUIPhotoAlbum pa = new GUIPhotoAlbum();
}
}
);
}

}

我在这里做错了什么?PS 我已经尝试使用 FileBufferedImageImageIcon ..并且我使用的是 Mac

最佳答案

Mac 不支持框架图标,如 this answer 所示。 .

关于java - setImageIcon 不在 mac swing 窗口上设置 JFrame 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23378119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com