java - Adding JComponent to JLabel dynamically -


i'm new in java , i'm trying draw graph dynamically in swing.

the window, has show first node automatically, hard coded this:

    lienzo = new lienzografos(this);     lienzo.setbounds(0, 0, 800, 200);      lienzo.anadircirculo(0, 50, 50);     pizarra.add(lienzo); 

pizarra white jlabel, lienzo jpanel class put nodes , arcs.

anadircirculo draw node in lienzo. variable n number shows @ side of node, , 2 others x , y coordenates.

to part, works perfect, run main code , have node waiting add others. if set mouse listener add new nodes each click, works fine too, can add want, , set arcs between them, not idea. i'm trying put new node, calling function

public void graficarrelacion(int x, int y){         int respuesta = joptionpane.showconfirmdialog(null, "desea relacionar " + x + " con " + y + "?" );         if(respuesta == joptionpane.yes_option){         lienzo.anadircirculo(x, 400, 200);        pizzara.add(lienzo);         test.revalidate();        test.repaint(); }} 

with this, i'm trying put new node in point 400,200 (who close middle of pizzara, , after put can drag anywhere want), have no answer in window when execute it. can call anywhere , node doesn't appear, when work same code, , use mouse listener instead this, works perfect.

what doing wrong?

edit:

this de definition of nodes

    public circulonodo(int n, int x, int y) {     this.n=n;     this.x=x;     this.y=y;     image = new imageicon("..desktop\\logo.png").getimage(); }  public void painter(graphics g,lienzografos l) {         g.drawimage(image, x-15, y-15, l);         g.setcolor(color.red);         g.drawstring(""+n, x-15, y-15);         g.drawstring(""+n, x-14, y-14);     } 

anadircirculo creates new object of circulonodo.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -