I am developing an application where I draw large number of lines (color is given as black) and update them where I need to remove them from screen.

I thought of making their color to match with the background so that I can make them hide. It seems to be simple and works but in the practical sense I have 10000 points and almost more than 20000 lines to be drawn and as most the line overlap or cross each other it is so disgusting the view.

So I need some kind of function to actually remove those selected lines between two known points from screen. Even I have a problem with the background color I can match the exact background default color of the applets. Can anyone suggest me solution or the color?

  • Could you add a screen shot of the problem you are having with the display?
    – user40980
    Apr 21, 2013 at 23:36

1 Answer 1


To draw usingbackground color can use http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#getBackground() which returns the background color, this can be set to the graphics object you are painting to.

Use double buffering, first clear the area by making a rectangle using default color :

g.setColor(backgroundColor); g.fillRect(0, 0, fullWidth, fullHeight);

and then draw only active lines. So no complicated algorithm, just start from a clean slate and draw only what is required

Refernece http://docs.oracle.com/javase/6/docs/api/java/awt/Graphics.html#setColor(java.awt.Color)

fillRect(int x, int y, int width, int height) on same page

Double buffering is explained here http://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html

and https://stackoverflow.com/questions/4430356/java-how-to-do-double-buffering-in-swing you could make your own image to process off screen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.