Setting background colour of JFrame

Discussion in 'Java' started by Scott Steiner, May 5, 2005.

  1. 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();
    }
    }
     
    Scott Steiner, May 5, 2005
    #1
    1. Advertisements

  2. Scott Steiner

    Roland Guest

    Set the color on the contentpane:
    this.getContentPane().setBackground(Color.BLACK);
    --
    Regards,

    Roland de Ruiter
    ___ ___
    /__/ w_/ /__/
    / \ /_/ / \
     
    Roland, May 5, 2005
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.