java - Swing - Adding line to exiting Panel doesn't show up -


i have jpanel points drawn @ start. trying add lines between these points, traverse between these points. lines not show up. if use repaint, previous drawing goes away. below code. need refresh in drawline code?

public void paintcomponent(graphics g) {     super.paintcomponent(g);     dodrawing(g); } //works fine private void dodrawing(graphics g) {     g.drawline(x, y, x, y); }  //called later outside, lines not show on panel public void drwaline(point p1, point p2) {     graphics g2d = getgraphics();     g2d.drawline(p1.getx(), p1.gety(), p2.getx(), p2.gety()); } 

if use repaint, previous drawing goes away.

yes, because whole component repainted again , first thing panel paint background clear old painting.

see custom painting approaches 2 common ways painting:

  1. use list hold objects want paint
  2. use bufferedimage.

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -