Java swing JLabel not showing

When exiting my game, I would like to show "exitscreen". Exitscreen.gif is located in the folder and works fine, but for some reason shows only an empty frame:

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 is another JFrame that I no longer need.

+3
source share
1 answer

Your code looks great and even works great for me. I think the problem is the location of the welcome.gif file.

Even at first I got a blank screen, but then I move welcome.gif to the right place, which is located directly under the root of the project.

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

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

+5

Source: https://habr.com/ru/post/1742237/


All Articles