java - Stable Line Custom Component -


i used following code create custom component draw edges of graphs, component has weird behaviors. appear right, doesn't appear. looked other custom component samples couldn't find problem. question problem?

public class edgeline extends jpanel { private static final long serialversionuid = -5820537358240087280l;  public final edge edge;  private int cheight; private int cwidth;  private line2d line;  public edgeline(edge edge) {     point firstlocation = edge.firstvertex.location;     point secondlocation = edge.secondvertex.location;      this.edge = edge;     cwidth = math.abs(firstlocation.y - secondlocation.y);     cheight = math.abs(firstlocation.x - secondlocation.x);      setsize(cheight, cwidth);     this.setbackground(new color(0, 0, 0, 0));      int xpoint = math.min(firstlocation.x, secondlocation.x);     int ypoint = math.min(firstlocation.y, secondlocation.y);      setlocation(new java.awt.point(xpoint, ypoint));      line = new line2d.float(firstlocation.x - xpoint, firstlocation.y - ypoint             , secondlocation.x - xpoint, secondlocation.y - ypoint); }  private void drawline(graphics2d graphic) {     graphic = (graphics2d) getgraphics();     graphic.setstroke(new basicstroke(6));     graphic.setcolor(color.orange);     graphic.draw(line); }  @override public void paintcomponent(graphics g) {     super.paintcomponent(g);     if (isopaque())      { //paint background         g.setcolor(getbackground());         g.fillrect(0, 0, getwidth(), getheight());     }     graphics2d graphic = (graphics2d) g.create();     drawline(graphic);     graphic.dispose(); }  @override public dimension getpreferredsize() {     dimension dim = new dimension(cheight, cwidth);     return dim; } } 


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -