JPanel not showing background image

后端 未结 2 1712
野趣味
野趣味 2021-01-22 19:27

It is very simple program and i have tried my best but the JPanel doesn\'t come up with a background image. I just want a simple background image on my panel.

Here is my

相关标签:
2条回答
  • 2021-01-22 20:19

    Don't use a JPanel. Just use a JLabel with an Icon then you don't need custom code.

    See Background Panel for more information as well as a solution that will paint the image on a JPanel with 3 different painting options:

    1. scaled
    2. tiled
    3. actual
    0 讨论(0)
  • 2021-01-22 20:26

    Replace

    public void printComponent(Graphics g) {
    

    with

    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
    
    0 讨论(0)
提交回复
热议问题