I m developing a java app that will have a GUI to draw the graph and implements the graph coloring algorithm to colour the nodes. I started with JFrame and Canvas and could draw lines and circles with paint() and repaint methods.. The problem is repaint method erases the previous info in the window.. i want to retain the nodes and edges drawn so far and continue drawing new edges.. I tried the overloaded version of repaint that repaints a portion but it is not efective.. i need to draw on the existing lines and nodesby overlapping them.. how can i go about it?
venktech
0
Newbie Poster
Recommended Answers
Jump to PostOverride paintComponent, not paint. This restricts your (re)paint to the client area only. Do not override repaint, just call it when necessary.
Do not call super.paintComponent in your paintComponent, because that's where the old content is being cleared. Just go ahead and paint the new stuff.
For more details see …
Jump to PostAnother solution is to create a working image with BufferedImage, draw your lines on the working image and then in the paintComponent method, draw the working image on the screen.
Your previously drawn figures would be preserved in the working image. This approach would be similiar to the double buffering …
All 5 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NormR1
563
Posting Sage
Team Colleague
venktech
0
Newbie Poster
venktech
0
Newbie Poster
venktech
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.