JGraph库未显示图形中的边

时间:2019-01-23 00:19:56

标签: java jgraphx jgraph

我写了一个基于JGraph库的类,它是JGraph开发团队编辑的Hello World的一部分。我在渲染图形时遇到了问题(可能是因为有用于存储数据的列表){ "emailList": [ [ "akki@gmail.com", "bakki@gmail.com" ], [ "lakki@gmail.com", "jakki@gmail.com" ] ] } [[akki@gmail.com bakki@gmail.com] [lakki@gmail.com jakki@gmail.com]] [91 91 34 97 107 107 105 64 103 109 97 105 108 46 99 111 109 34 44 34 98 97 107 107 105 64 103 109 97 105 108 46 99 111 109 34 93 44 91 34 108 97 107 107 105 64 103 109 97 105 108 46 99 111 109 34 44 34 106 97 107 107 105 64 103 109 97 105 108 46 99 111 109 34 93 93] [["akki@gmail.com","bakki@gmail.com"],["lakki@gmail.com","jakki@gmail.com"]] ,因为我可以正确看到所有节点/顶点,但是没有边缘/连接。

当前图形的图像:

image of my graph here

我的输入数据:

because I see just one node/vertex in graph and nothing more. -that's solved for now

拆分后和首次上市前的数据

A
B
C
D
E

A,B
B,C
D,E

现在是我编写的实际代码...

listOfNodes: [A, B, C, D, E] (probably, not sure)
nodesA: [A, B, D]
nodesB: [B, C, E]

因此,我想要所有顶点/节点以及它们之间的边/连接。我怎么说,实际上我有import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.view.mxGraph; import javax.swing.*; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Random; public class RenderGraph extends JFrame{ List<String> nodesA = new ArrayList<>(); List<String> nodesB = new ArrayList<>(); public void getRender(File file) { IntFileReaderEngine fr = new FileReaderEngine(); fr.readFile(file); ConsoleProcessor cp = new ConsoleProcessor(); //Graph creating //Getting random number Random RandomNumber = new Random(); int n1 = RandomNumber.nextInt(200) ; int n2 = RandomNumber.nextInt(200) ; mxGraph graph = new mxGraph(); Object parent = graph.getDefaultParent(); graph.getModel().beginUpdate(); //Lists for storing objects List<Object> listOfNodes = new ArrayList<>(); List<Object> listOfEdges = new ArrayList<>(); try { for(int i=0; i<fr.getNodes().size();i++){ String pom = fr.getNodes().get(i); Object point = graph.insertVertex(parent, null, pom, n1, n2, 20, 20); listOfNodes.add(point); } for(String str:fr.getConnections()) { String[] nodes = str.split(","); nodesA.add(nodes[0]); nodesB.add(nodes[1]); } for(int i=0; i<nodesA.size(); i++){ if(nodesA.get(i) != nodesB.get(i)){ Object A=null; Object B=null; if(listOfNodes.indexOf(nodesA.get(i)) != -1){ A=listOfNodes.get(listOfNodes.indexOf(nodesA.get(i))); } if(listOfNodes.indexOf(nodesB.get(i)) != -1){ B=listOfNodes.get(listOfNodes.indexOf(nodesB.get(i))); } listOfEdges.add(graph.insertEdge(parent, null, "", A, B)); } } } finally { graph.getModel().endUpdate(); } mxGraphComponent graphComponent = new mxGraphComponent(graph); getContentPane().add(graphComponent); RenderGraph frame = new RenderGraph(); frame.add(graphComponent); frame.pack(); frame.setVisible(true); } } 所有节点/顶点,但仍然没有连接/边。

0 个答案:

没有答案