I am coding a little program and this is basically my first time to using a JComponent to draw stuff. I set the background of the component to black.
But as soon as I draw a JButton in it, it gets overwritten by the default grey. I have been searching for this for an hour now and can't seem to find any answers.

What you are seeing is the frame to which you have added your JComponent, so if you want a black background frame then you need to set the background color of JFrame.
Something like this:
JFrame frame = new JFrame();
frame.add(new GUI());
frame.pack();
frame.getContentPane().setBackground(Color.black);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
try setting the button to opaque use the setOpaque(boolean opaque); method
I'm not sure if I'm right but I might be
Edit:
Try using these methods:
button.setBorderPainted(false);
button.setContentAreaFilled(false);
button.setFocusPainted(false);
button.setOpaque(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With