• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in setting the background of a frame

 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2565
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic