Alternating AWT graphics colour

It is possible to draw 2D colours in such a way that it inverts colours behind it, like in the screenshot below:

line colour

This can be done by enabling “XOR Colour mode” and by using…


…this is because white has an RGB value of 255,255,255, and XOR’ing these values will cause the alternating effect.

The following code example shows this:

graphics.drawLine(x, delegate.getXAxisHeight(), x, delegate.getDiagramRect().height + delegate.getXAxisHeight());

Don’t forget to save the previous colour (using graphics.getColor())and then reset it after drawing this alternative-coloured line.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s