Forums Register Login

background color is not changing?

+Pie Number of slices to send: Send
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]
2
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
sorry, i forgot to add code tags..
and thanks...
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3157 times.
Similar Threads
Developing Games In Java chapter 2 example not doing as i would have expected
Images don't painting
Drawing An Image In Full-Screen
nullPointerException found regarding Window
A flatland puzzle
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:25:03.