im drawing a bargraph with this paint method, and the bars a a dark gray. I just wanted to know how to get that color back when i change back and forth?
is there a Color.DEFAULT or something like that? Or should i just setColor before the the loop
public void paint(Graphics g) {
super.paint(g);
for (int i = 0, k = 0; i < barsArray.length; i++, k += getWidth()
/ barsArray.length) {
g.fillRect(k + 5, getHeight() - barsArray[i] * 15, getWidth()
/ barsArray.length - 1, getHeight() * 2);
}
}
You could use g.getColor()
before you change it.
It might not be suitable to override paint
, instead, you should consider overriding paintComponent
of a class that extends from JComponent
Take a look at Performing Custom Painting for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With