File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Problem in setting the background of a frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in setting the background of a frame" Watch "Problem in setting the background of a frame" New topic
Author

Problem in setting the background of a frame

Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 103

Dear all,

the code is as follows.








The problem is when the frame launches, there is no background color set.
but when I resize it, the background shows the color which i set but only during resizing.
What might be the problem and how to remove it.

Please Help..

Thanks in advance.

[jc: added code tags]
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2500
    
    8

Hi, Prash

Can you use code tags in stead of colors to mark your code?
The code tag button is just above right to the color selector.

You can edit your post by clicking on the edit button on the right side of your post.


OCUP UML fundamental and ITIL foundation
youtube channel
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10375
    
    8

Your code works for me.
However, you might want to try using the SwingUtilities#invokeLater() as discussed here http://java.sun.com/javase/6/docs/api/javax/swing/package-summary.html#threading


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 103

Dear Maneesh,

Thanks for your reply.

But could you please tell me what effect is invokeLater() method gonna cause?

I tried this code, but i am still getting the same problem.

I also tried
this.getContentPane().setBackground(Color.RED);

But no change..!!


Please help..

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
Setting the background of the frame doesn't work because "the content pane" is added to the frame, so you see the background of the content pane. So you need to set the background color of the content pane.

Read the section from the Swing tutorial on Using Top Level Containers to understand how a frame works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in setting the background of a frame