Setting background colour of JFrame

S

Scott Steiner

Hi,

I can't seem to set the background colour of a JFrame. When the Frame is
loaded then I see the correct colour for a split second but then it's
gone. Here is the very simple sample code, any help much appreciated:

import javax.swing.*;
import java.awt.*;

public class Test extends JFrame
{
public Test()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,500);
this.setBackground(Color.BLACK);
this.setVisible(true);
}

public static void main(String[] args)
{
new Test();
}
}
 
R

Roland

Hi,

I can't seem to set the background colour of a JFrame. When the Frame is
loaded then I see the correct colour for a split second but then it's
gone. Here is the very simple sample code, any help much appreciated:

import javax.swing.*;
import java.awt.*;

public class Test extends JFrame
{
public Test()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,500);
this.setBackground(Color.BLACK);
this.setVisible(true);
}

public static void main(String[] args)
{
new Test();
}
}
Set the color on the contentpane:
this.getContentPane().setBackground(Color.BLACK);
--
Regards,

Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top