Forums Register Login

Problem changing colours

+Pie Number of slices to send: Send
Hi guys

I currently have a small problem with drawing different colours to my JPanel. I currently have buttons that changes the value of an int (colourStatus) when pressed. it also calls a method to change the colour, based upon the status selected.



now that i hve the colour selected, i apply before drawing my shapes



the problem is the colour changes just fine, but all other lines draw on the screen also change to the new colour, is there a way i can just apply changes to any new lines that are drawn

Thanks Nick
+Pie Number of slices to send: Send
How about storing the color in your Line instances, and use that color? That way each Line instance knows its own color.
+Pie Number of slices to send: Send
Well, the lines are going to be redrawn repeatedly. If you want "change colour" to mean "Any new lines should be this new colour but the old lines should still be drawn with whichever colour they were originally drawn with", then you'll need a data structure which keeps track of what colour a line should be redrawn with, when it's redrawn.
+Pie Number of slices to send: Send
Custom Painting Approaches has an example that does this with Rectangles.
+Pie Number of slices to send: Send
Cheers guys, all the help was appriciated, have managed to implement the change colour by passing the colour each time the object is created.

Thanks again Nick
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 723 times.
Similar Threads
How to change the colour of an JTable Cell dynamically
Tree and drawing within the same panel
crazy lecturers and tricky questions
Random to the colour object
Drawing text inside a Graphics2D shape
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 03:56:44.