IAmBlake IAmBlake - 8 days ago 5
Java Question

How to add a icon in JButton

I'm trying to create a icon in a button in JButton, the button should look like this

enter image description here

But when i add this in my code it looks like this

enter image description here

Here is the button portion of my code

private JButton backButton = new JButton();
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
actionBack();
}
});
backButton.setIcon(new ImageIcon(Hello.class.getResource("/239706184.png")));
backButton.setEnabled(false);
buttonPanel.add(backButton);

Answer

Your button is dark because you set eneable to false

remove this line:

backButton.setEnabled(false);