Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem in setting the background of a frame

 
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Bartender
Posts: 2659
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..

 
Rancher
Posts: 3248
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic