How to set Jframe Background Image in GroupLayout Java

前端 未结 3 382
春和景丽
春和景丽 2021-01-23 06:26

Am trying to set a background image for my frame but it does not work. I tried this link:

Setting background images in JFrame

The code:

setConten         


        
3条回答
  •  春和景丽
    2021-01-23 07:03

    I've an inkling the problem may lie with

    setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("/Images/about.png")))));
    

    Try removing the leading slash in the file path, as this may be interpreted differently based on the OS:

    setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("Images/about.png")))));
    

提交回复
热议问题