I have the code shown below:
public VizCanvas(){
{
this.setBackground(Color.black);
this.setSize(400,400);
}
}
It worked fine and displays the panel in black background. But when I implement the paint method, which does nothing, the color changes to default color i.e gray.
I tried to set graphics.setColor() but it didn’t help.
You need to do a fill of the canvas to your background colour in the painting method. Something along the lines of:
After that, draw whatever you need to. You could also try calling
super.paint(g)in the paint method instead before doing anything.