简体   繁体   English

java jbutton image png可点击区域

[英]java jbutton image png clickable area

I want to do a JButton with PNG icon but the clickable area have to be a pixel and not a transparency pixel, and position this JButton over other JButton s like position absolute in css. 我想用PNG图标做一个JButton但是可点击区域必须是一个像素而不是透明像素,并将这个JButton定位在其他JButton就像在css中的绝对位置一样。

thanks in advance 提前致谢

Create a JLabel with the imge and add a MouseListener. 使用imge创建一个JLabel并添加一个MouseListener。 In the listener check Point of the MouseEvent. 在监听器中检查MouseEvent的Point。 Get pixel from the image for the point and check alpha of the image's point color. 从图像中获取点的像素,并检查图像的点颜色的alpha。 If it's not transparent do your action. 如果它不透明你的行动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM