Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

background color is not changing?

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, i forgot to add code tags..
and thanks...
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic