how do you create a JButton with a particular shape? here I want the shape of a pen, ie I want it to be clickable only on the surface of the pen. Thanks!
Asked
Active
Viewed 99 times
0
-
See [Creating a custom button in Java with JButton](https://stackoverflow.com/questions/5751311/creating-a-custom-button-in-java-with-jbutton). Good luck. It will take a lot of effort. – Gilbert Le Blanc Jan 02 '23 at 21:43
-
1Your "basic" question comes to basic "collision detection" - given a x/y position (ie mouse click), is the x/y position within the bounds of the pen. The difficult part for you is trying to "map" the pen to something which can be easily compared to. You "could" look at the pixels, if they are non-alpha, then you're probably within the pen or you could create a "mapping" shape (more difficult, but easy to deal with it) which defines the a "clickable" area - all of these have been asked and answered before, I suggest some additional research into the topics – MadProgrammer Jan 02 '23 at 22:18
-
Do you need it the component to be a `JButton` or is it enough if it is just a "clickable shape" (https://stackoverflow.com/questions/21355434/create-clickable-graphics-java)? – Thomas Kläger Jan 02 '23 at 22:21
-
Following up on @MadProgrammer comment you would override the `contains(...)` method of the button to determine if the click occurred on a non transparent pixel. – camickr Jan 03 '23 at 15:18
-
d'accord merci pour vos réponses, ! – Riské Jan 04 '23 at 09:07