Is it possible to create buttons in shapes other than rectangles (or rounded rectangles). Could you, for instance, create a button in the shape of a state on a map? Would clicking anywhere in the shape cause a MouseEvent to be broadcast?
Is it possible to create buttons in shapes other than rectangles (or rounded rectangles).
Share
You can create such buttons by extending JButton and calling
setContentAreaFilled(false);in the constructor. Then you can paint whatever you like in the overridden
paintComponent()method. Also you need to override thecontains()method ofJComponentto provide desired mouse hit-test. In this method you can call polygon’s (the one used for drawing the button)contains()method.