What is the default color when starting the drawing method

im draw a bargraph with this drawing method and the stripes are dark gray. I just wanted to know how to bring this color back when I go back and forth?

is there a color .DEFAULT or something like that? Or should I just setColor before 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);
    }
}
+4
source share
2 answers

You can use g.getColor()before changing it.

This may not be suitable for overriding paint, instead you should consider overriding a paintComponentclass that continues fromJComponent

See Performing Custom Painting for more details.

+7

" setColor...", Graphics, , , .

( ):

  • , (, Graphics):

Color oldColor = g.getColor();

// do something with g

g.setColor(oldColor);

  • (, Graphics):

Graphics gCopy = g.create();

// do something with gCopy

gCopy.dispose();

0

Source: https://habr.com/ru/post/1536289/


All Articles