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?