Creating custom JButton from images containing transparent pixels

前端 未结 6 558
悲哀的现实
悲哀的现实 2020-12-02 00:46

Read edit 2 for what I\'m actually missing to make it work

I\'m currently trying to create some custom JButtons using images created in photoshop that have an

6条回答
  •  既然无缘
    2020-12-02 00:54

    If you want your button layout to be that of the non-transparent pixels in your image, then you should redefine the paintComponent() method. It is the most correct way of doing it (overriding paint() worked in old times but is now discouraged).

    However I think it is not exactly what you want: you want a click on the button to be detected only if it is on a non-transparent pixel, right? In that case you have to parse your image and when clicked compare mouse coordinates to the pixel alpha channel of your image as JButton does not have such a feature.

提交回复
热议问题