我有一个没有显示的ImageIcon的JLabel。
public class Lockscreen extends JFrame {
JPanel layer;
JButton signin;
ImageIcon heartlock;
String heartlockpath;
JLabel heartlockdisplay;
String arrowpath;
public Lockscreen(){
super("Startseite");
setSize(700, 400);
setLocation(100, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
arrowpath = "C:\\Users\\saydanan\\Pictures\\FürMyDiary\\Right_Arrow.png";
signin = new JButton();
signin.setSize(19, 12);
signin.setIcon(new ImageIcon(arrowpath));
signin.setLocation(250, 500);
heartlockpath = "C:\\Users\\saydananPicturesFürMyDiary\\082326-green-jelly-icon-business-lock-heart.png";
heartlock = new ImageIcon(heartlockpath);
heartlockdisplay = new JLabel();
heartlockdisplay.setIcon(heartlock);
heartlockdisplay.setLocation(250, 250);
heartlockdisplay.setSize(heartlock.getIconWidth(), heartlock.getIconHeight());
heartlockdisplay.setVisible(true);
layer = new JPanel();
layer.setBackground(Color.black);
/*layer.setLayout(...);*/
addEverything(layer);
getContentPane().add(layer);
setVisible(true);
}
public void addEverything(JPanel panel){
panel.add(signin);
panel.add(heartlockdisplay);
panel.repaint();
}
}
答案 0 :(得分:-1)
您需要添加它,然后将其设置为可见。
如:
panel.add(heartlockdisplay);
heartlockdisplay.setVisible(true);
panel.setVisible(true);