我有一个类扩展JButton
,我试图应用.png图像.图像形状不规则,并被透明像素包围.我已经覆盖了paintComponent()
方法,在JButton
我的缓冲图像应用到按钮.现在,图像是唯一被绘制的东西,这就是我想要的.
但是,按钮仍然会检测周围矩形中的事件.有没有办法将检测限制在仅包含不透明像素的区域(或者更确切地说不检测透明像素上的事件)?
按钮类的代码如下.
public class DrawButton extends JButton{
private BufferedImage bi;
public DrawButton(BufferedImage bi){
setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight()));
this.bi = bi;
}
@Override
protected void paintComponent(Graphics g){
g.drawImage(bi, 0, 0, null);
g.dispose();
}
}
Run Code Online (Sandbox Code Playgroud)