Using an image for the background of a JPanel and JButton

后端 未结 1 1300
眼角桃花
眼角桃花 2021-01-28 19:13

I am trying to use an image I made in photoshop as the background for my GUI. How do I do that? also I made some images I want to display in the button backgrounds after the a

相关标签:
1条回答
  • 2021-01-28 19:30

    For the JButton, use this:

    JButton button = new JButton("Button Name", new ImageIcon("foo.png");
    

    The Panel is a bit more interesting. This is a good method, though:

    ImagePanel panel = new ImagePanel(new ImageIcon("foo.png").getImage());
    
    0 讨论(0)
提交回复
热议问题