Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default color when I run the paint method

Tags:

java

swing

paint

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);
    }
}
like image 411
user3528168 Avatar asked Mar 19 '23 21:03

user3528168


1 Answers

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

like image 62
MadProgrammer Avatar answered Apr 01 '23 08:04

MadProgrammer