【问题标题】:Java swing JLabel not showingJava swing JLabel 未显示
【发布时间】:2010-04-22 07:33:26
【问题描述】:

在退出我的游戏时,我想显示一个“退出屏幕”。 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。

【问题讨论】:

    标签: java swing jframe


    【解决方案1】:

    您的代码看起来不错,甚至对我来说也可以正常工作。我想问题是welcome.gif 文件的位置。

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-11
      • 2017-05-26
      • 2013-12-08
      • 2012-10-31
      • 2022-07-12
      • 2010-12-19
      • 2023-03-25
      • 1970-01-01
      相关资源
      最近更新 更多