• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1441
  • Last Modified:

frame.setBackground(Color c)

I have a window with 4 frames. setBackground(Color c) for the window works OK. The background
between the frames is OK but I can't get the backgroung of the frames to work.
    Color bgcolor = new Color(100, 100, 255);
    Color fgcolor = new Color(255, 255, 255);
        // Create a Panel to contain all the components along the
        // left hand side of the window.  Use a GridBagLayout for it.
        panel1 = new Panel();
        panel1.setBackground((Color) bgcolor);
No matter what I try the panel background stays gray.
1 Solution
This might be an answer: try calling this.validate() after setting up the layout to ensure the paint() methods get called; I think your applet is staying the default grey because it's not being repainted.

Mark King
sandbarAuthor Commented:
I don't know if it makes a difference but this is an application not applet. Anyway the
validate idea did't work.
Try adding the component *before* setting the background color,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now