繁体   English   中英

Java swing JLabel没有显示

[英]Java swing JLabel not showing

在退出我的比赛时,我想展示一个“退出”。 exitscreen.gif在文件夹中,工作正常,但由于某种原因,只有空白框显示:

JPanel finishPanel = new JPanel();
JLabel finishLabel = new JLabel(new ImageIcon("welcomescreen.gif"));
finishPanel.add(finishLabel);
finishLabel.setSize(11 * 35, 11 * 35);
finishPanel.setPreferredSize(finishLabel.getSize());
this.frame.setVisible(false);
JFrame exitFrame = new JFrame("Thanks for playing");
exitFrame.getContentPane().add(finishPanel);
exitFrame.setLocationRelativeTo(null);
exitFrame.pack();
exitFrame.setVisible(true);
finishLabel.setVisible(true);

this.frame只是我不再需要的另一个JFrame。

你的代码看起来很好,甚至对我来说都很好。 我想问题是welcome.gif文件的位置。

即使我先得到一个空白屏幕,然后我将welcome.gif移动到项目根目录下的正确位置。

http://img15.imageshack.us/img15/4821/screenshotuct.png

http://img693.imageshack.us/img693/6301/locationy.png

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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