Java: using an image as a button

后端 未结 9 2346
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 02:53

I would like to use an image as a button in Java, and I tried to do this:

BufferedImage buttonIcon = ImageIO.read(new File(\"buttonIconPath\"));
button = new         


        
相关标签:
9条回答
  • 2020-11-30 03:38

    buttonIcon.setBorder(new EmptyBorder(0,0,0,0));

    0 讨论(0)
  • 2020-11-30 03:38

    just write this

    button.setContentAreaFilled(false);
    
    0 讨论(0)
  • 2020-11-30 03:40

    A suggestion would be to set the Image as a label and add a mouse listener to the label to detect clicks.

    Example:

    ImageIcon icon = ...;
    
    JLabel button = new JLabel(icon);
    
    button.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
         ... handle the click ...
      }
    });
    
    0 讨论(0)
提交回复
热议问题