Setting a background image on a JFrame using Swing

前端 未结 2 1299
被撕碎了的回忆
被撕碎了的回忆 2020-12-21 23:52

I have been learning Java for a few weeks now and I am really stuck when it comes to applying a background image to a JFrame. Every tutorial I\'ve come across doesn\'t creat

2条回答
  •  醉梦人生
    2020-12-22 00:08

    Better to use:

    ImageIcon closeImg = new ImageIcon(getClass().getResource("\\images\\buttons\\closeBtn.png"));
    

    Make sure your image is located in the same location relative to where your class file is output.

    Also your close button calls setVisible(false) but does not dispose of any resources or exit the application.

提交回复
热议问题