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
, in order to play with the positions and the size of the button (that's why I have to put true
the setOpaque()
, otherwise the color is not seen):
this.setLayout(null);
The problem is that the result is not what I expected, the button is not painted, but an outer contour as can be seen in the image:
How do I have to do it?
For some strange reason the 'Aqua Look & Feel' Java theme for OS X doesn't let you do this any easier. Once I chose to change the visual theme and then yes. for instance:
... and boom: