Java: using an image as a button

后端 未结 9 2362
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  萌比男神i
    2020-11-30 03:29

    As far i know, there is no easy way of doing it, you will need to override the "paintComponent" method of the JButton class to aint your image, if you only want to display an image and behave like a button, you can add a JPanel wich draws the image (clicky) and add a MouseListener/MouseAdapter to handle the "mousePressed" event

提交回复
热议问题