java - JUNG: Paint graph on existing JPanel -


i starting jung , draw graph in jpanel of newly created jframe, unable paint same graph in existing panel of program developing.

the function use this:

private void demograph() {         // graph<v, e> v type of vertices , e type of edges         // note showing use of sparsegraph rather sparsemultigraph         graph<integer, string> g = new sparsegraph<>();         // add vertices. above defined these type integer.         g.addvertex((integer) 1);         g.addvertex((integer) 2);         g.addvertex((integer) 3);         // g.addvertex((integer)1);  // note if add same object again nothing changes         // add edges. above defined these of type string         // note default undirected edges.         g.addedge("edge-a", 1, 2); // note java 1.5 auto-boxes primitives         g.addedge("edge-b", 2, 3);          // layout<v, e>, visualizationcomponent<v,e>         layout<integer, string> layout = new circlelayout(g);         layout.setsize(new dimension(300, 300));         visualizationviewer<integer, string> vv = new visualizationviewer<>(layout);         vv.setpreferredsize(new dimension(350, 350));         // setup new vertex paint transformer...         transformer<integer, paint> vertexpaint = new transformer<integer, paint>() {             @override             public paint transform(integer i) {                 return color.green;             }         };         // set new stroke transformer edges         float dash[] = {10.0f};         final stroke edgestroke = new basicstroke(1.0f, basicstroke.cap_butt,                 basicstroke.join_miter, 10.0f, dash, 0.0f);         transformer<string, stroke> edgestroketransformer = new transformer<string, stroke>() {             @override             public stroke transform(string s) {                 return edgestroke;             }         };         vv.getrendercontext().setvertexfillpainttransformer(vertexpaint);         vv.getrendercontext().setedgestroketransformer(edgestroketransformer);         vv.getrendercontext().setvertexlabeltransformer(new tostringlabeller());         vv.getrendercontext().setedgelabeltransformer(new tostringlabeller());         vv.getrenderer().getvertexlabelrenderer().setposition(position.cntr);           // paint on jpanel: not working         graphzoomscrollpane panel = new graphzoomscrollpane(vv);         panel.setsize(this.graphpanel.getwidth(), this.graphpanel.getheight());         borderlayout panelmaplayout = new borderlayout();         panel.setlayout(panelmaplayout);         panel.setvisible(true);         this.graphpanel.add(panel);         this.graphpanel.revalidate();         this.graphpanel.repaint();          // paint on new jframe: working         jframe frame = new jframe("simple graph view 2");         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.getcontentpane().add(vv);         frame.pack();         frame.setvisible(true);     } 

some guidance here appreciated.

i think you've forgotten add gui panel. see:

frame.getcontentpane().add(vv); 

should be:

this.graphpanel.add(vv); frame.getcontentpane().add(this.graphpanel); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -