how can i put a JButton on an image?

后端 未结 4 1693
终归单人心
终归单人心 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:16

    Have you tried using a JLabel with HTML in the label? Something like this:

    import javax.swing.*;
    
    public class SwingImage1
    {
      public static void main( String args[] )
      {
        JFrame  frm = new JFrame( "Swing Image 1" );
        JLabel  lbl = new JLabel( "" );
        frm.getContentPane().add( lbl );
        frm.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frm.pack();
        frm.setVisible( true );
      }
    }
    

    then on top of your label you can add your button?

提交回复
热议问题