Forcing JButton Not To Draw Background

I am coding a small program, and this is basically my first experience JComponentwith drawing. I set the component background to black.

But as soon as I draw JButtonin it, it will be overwritten in gray by default. I searched for this for an hour and cannot find the answers.

2YF3s.png

+3
source share
2 answers

What you see is the frame you added your own to JComponent, so if you need a black background frame, you need to set the background color of the JFrame.

Something like that:

JFrame frame = new JFrame();
frame.add(new GUI());
frame.pack();
frame.getContentPane().setBackground(Color.black);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
+1
source

try setting an opaque button using setOpaque (boolean opaque); Method

I'm not sure I'm right, but maybe

Edit:

Try using the following methods:

 button.setBorderPainted(false); 
 button.setContentAreaFilled(false); 
 button.setFocusPainted(false); 
 button.setOpaque(false);
+1
source

All Articles