I want to change the background image of a JButton in swing,
The method :
Button.setIcon (),
Set’s the icon only not the background,
Is there a easy way to do that?
You can still use setIcon
but you will need to set the alignment to make the text appear over the image
button.setHorizontalTextPosition(SwingConstants.CENTER);
One option is to subclass JButton, override paintComponent() method and paint the icon there.
The easy way use SynthLookAndFeel as described here or you could go with creating a class that extends JButton and provide a new implementation of paintComponent(Graphics g)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With