Reputation: 515
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?
Upvotes: 5
Views: 9602
Reputation: 159754
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);
Upvotes: 5
Reputation: 548
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)
Upvotes: 3
Reputation: 8874
One option is to subclass JButton, override paintComponent() method and paint the icon there.
Upvotes: 4