Reputation: 1849
Let's say i have a Jbutton where it has both ImageIcon and text, is it possible to set background color to icon filling it's buttons width?
Upvotes: 1
Views: 460
Reputation: 18792
Consider setting the button's background and using an icon with transparent background:
JButton button = new JButton("Sweety");
URL url = new URL("https://findicons.com/files/icons/345/summer/128/cake.png");
button.setIcon(new ImageIcon(url));
button.setVerticalTextPosition(SwingConstants.BOTTOM);
button.setHorizontalTextPosition(SwingConstants.CENTER);
button.setBackground(Color.YELLOW);
Upvotes: 1