[英]Java - JFrame not displaying ImageIcon
public Vue(String title) {
super(title);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.getContentPane().setLayout(new GridLayout(4, 1));
JPanel p1 = createPanel1();
this.getContentPane().add(p1);
JPanel p2bis = createPanel2bis();
this.getContentPane().add(p2bis);
JPanel p3 = createPanel3();
this.getContentPane().add(p3);
this.setJMenuBar(createMenuBar());
this.setPreferredSize(new Dimension(750,400));
this.pack();
this.setVisible(true);
ImageIcon image = new ImageIcon(getClass().getResource("voile.png"));
this.setIconImage(image.getImage());
System.out.println(image.getDescription());
}
Hi, 嗨,
I spent time to find the solution to display my image as a JFrame icon image... And tryed a lot of things like 我花了一些时间来找到解决方案,以将我的图像显示为JFrame图标图像...并且尝试了很多类似的操作
ImageIcon image = new ImageIcon(Constants.LOGO_ABSOLUTE_PATH);
this.setIconImage(image.getImage());
System.out.println(image.getDescription());
I put "voile.png" file everywhere in my directories : root,src,bin and inside bin and src packages. 我将“ voile.png”文件放在目录中的所有位置:root,src,bin以及bin和src包中。 I also tryed with an online logo and its URI.
我还尝试了在线徽标及其URI。
However, it actually doesn't work. 但是,它实际上不起作用。 If anyone can help me ?
如果有人可以帮助我?
I'm running it on Eclipse Oxygen and Windows 10 我正在Eclipse Oxygen和Windows 10上运行它
PS : System.out.println(image.getDescription()); PS:System.out.println(image.getDescription()); always showing a path where my image is located (Anyway I put it everywhere)
总是显示我的图片所在的路径(无论如何,到处都放置它)
ImageIcon doesn't support PNG transparency. ImageIcon不支持PNG透明度。 I had to create a blank jpg image and put logo inside.
我必须创建一个空白的jpg图像,然后在其中放置徽标。 My final code is
我的最终代码是
ImageIcon image = new ImageIcon(Constants.LOGO);
this.setIconImage(image.getImage());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.