Question: I want to change the color of JButton by:

```
JButton button = new JButton();

button.setBackground(Color.decode("#00a5ff"));

```

In order for change to occur, I have to add:

```
button.setOpaque(true);
button.setBorderPainted(false);

```

However, this remove the curves around the edges and thus changes the shape of the button. Is there a way to just simply change to color and keep the other properties? Another example is the changing of color (getting darker) when you press a button without having changed its color.

Here is some code that illustrates the difference between the two buttons:

```
    public static void main(String[] args) {
    JFrame frame = new JFrame("frame");
    frame.setSize(new Dimension(300, 300));
    JButton button1 = new JButton();
    JButton button2 = new JButton();

    button1.setPreferredSize(new Dimension(100,100));
    button2.setPreferredSize(new Dimension(100,100));
    button2.setBackground(Color.decode("#00a5ff"));
    button2.setBorderPainted(false);
    button2.setOpaque(true);

    JPanel pane1 = new JPanel(new FlowLayout());
    JPanel pane2 = new JPanel(new FlowLayout());

    pane1.add(button1);
    pane2.add(button2);
    frame.add(pane1, BorderLayout.WEST);
    frame.add(pane2, BorderLayout.EAST);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

```

Thanks

Answer: 
I literally just tested the following:

```
JFrame frame = new JFrame("frame");
frame.setSize(new Dimension(300, 300));
JButton button = new JButton();

button.setBackground(Color.decode("#00a5ff"));
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

```

It seemed to work, but I am working on Ubuntu Studio 16.04. If you notice that it does not work, then let me know. Could you please show the result of your white button or your failed button (if it still doesn't work)?
Perhaps you have something else going on in your code. I altered a small example I have and the color changes with only setBackground(Color) using regular Button and using JButton. See the following...

```
public static void main(String[] args) {
    Frame frame = new Frame();
    Panel panel = new Panel();
    Button closeButton = new Button("Close");
    closeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            frame.setVisible(false);
            frame.dispose();
        }           
    });
    closeButton.setBackground(Color.decode("#00a5ff"));
    panel.add(closeButton);
    frame.add(panel);
    frame.setSize(200, 100);
    frame.setLocation(200, 50);
    frame.setVisible(true);
}

```