how can i put a JButton on an image?

后端 未结 4 1639
终归单人心
终归单人心 2020-12-18 07:54

I am trying to fix a JFrame where there will be a background image and on the image JButtons which will do some commands. I try to do it without layout because i want to pu

4条回答
  •  隐瞒了意图╮
    2020-12-18 08:04

    You should swap those two lines:

    super.paintComponents(g);  //paints the children, like the button
    g.drawImage(background, 0, 25, null); // draw background later possibly overwriting the button
    

    Thus it should be this order:

    g.drawImage(background, 0, 25, null);
    super.paintComponents(g); 
    

    Additionally, note that the content pane's default layout is BorderLayout. Thus you'd set the layout of your content pane to null explicitly.

提交回复
热议问题