Java change color to JButton Mac OS X

0

I am inserting the following button in a JPanel as follows:

JButton button = new JButton();
button.setBounds(50, 50, 40, 40);
button.setBackground(Color.RED);
button.setOpaque(true);
this.add(button);

Add that I have the layout of the JPanel as null , to play with the positions and the size of the button (that's why I have to put true the setOpaque() , otherwise, you can not see the color):

this.setLayout(null);

The problem is that the result is not as expected, I do not paint the button, but an outer contour as you can see in the image:

How do I have to do it?

    
asked by Ibrahim Hernández Jorge 05.07.2017 в 21:48
source

1 answer

1

For some strange reason the theme 'Aqua Look & Feel 'from Java to OS X does not let this be possible at least easier. Once I chose to change the visual theme and then yes. for example:

try {
  javax.swing.UIManager.setLookAndFeel( "javax.swing.plaf.nimbus.NimbusLookAndFeel" );
} catch( Exception e ) {
  e.printStackTrace();
}

... and boom:

    
answered by 06.07.2017 / 01:59
source