wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes background color is not changing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "background color is not changing?" Watch "background color is not changing?" New topic
Author

background color is not changing?

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
hello i m having some problem in the below code, my background color is not going to change to green, can anyone tell me why?
and also how can i set an image as my background here?



[VK: Added code tags]
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2156
    
    7
After over 70 postings on the forum you should know how to use the "code formatting tags" so the code you post is formatted and readable.

You need to change the background of the content pane, not the JFrame.

Read the section from the Swing tutorial on Custom Painting for the proper way to do this. You should NOT override the paint() method.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
sorry, i forgot to add code tags..
and thanks...
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
As you said, i replaced my run method like:



now i m able to get my background color, but now my text

g.drawString("Hello it's me punit.", 200, 200);

is not visible.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2156
    
    7
1) Still didn't paste the code properly. I'm sure you don't write code left justified, so don't expect use to read it like that.

2) Can't tell what you are doing because you didn't post a proper SSCCE.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

No no no no no. That was my first reaction when I saw your code. You are blocking the Event Dispatcher Thread with your sleep call, and that causes the entire user interface to block. Please read Concurrency in Swing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: background color is not changing?
 
Similar Threads
nullPointerException found regarding Window
Drawing An Image In Full-Screen
Images don't painting
A flatland puzzle
Developing Games In Java chapter 2 example not doing as i would have expected