Set background color in Java on a JPanel doesn't work
java, jpanel
Solution
This could fix it...
public class Container extends JPanel
{
public Container()
{
super();
this.setOpaque(true);
this.setBackground(Color.WHITE);
}
}
Problem
I am working on a "paint-like" application (a little drawing software) to familiarize with Java 2D components. Here is my problem: I have a JFrame whose ContentPane is an instance of a class inheriting from JPanel. I want to set the background color to white but it remains on its default color... The class name corresponding to ContentPane is Container. Here is a simplified code: ``` public class Container extends JPanel { public Container() { super(); this.setBackground(Color.WHITE); } } ``` The JFrame constructor contains the line: ``` this.setContentPane(mainContainer); ``` Have I missed something? Thx.