我一直在尝试使用JavaFX在GUI中显示使用GraphStream生成的Graph。这是我到目前为止所拥有的
Graph graphInit = new Graph(); //class that handles graph population
SingleGraph graph = new SingleGraph("Graph"); //GraphStream Class
SwingNode graphViewer = new SwingNode(); //JavaFX Component to display Swing elements
graph = graphInit.genGraph(graph);
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
View view = viewer.addDefaultView(false); // false indicates "no JFrame".
graphViewer.setContent((JComponent) view);
graphHook.getChildren().add(graphViewer);
graphViewer是一个SwingNode组件。
我认为GraphStream还不支持JavaFX,但我不确定。另外,我发现gs-fx我不知道如何使用。
任何帮助将不胜感激。如果有一些像GraphStream这样的其他库来生成图形并在GUI中显示它,那也可以。
答案 0 :(得分:0)
public void imagesie(Graph g){
FileSinkImages pic = new FileSinkImages(OutputType.PNG, Resolutions.HD1080);
g.display();
pic.setLayoutPolicy(LayoutPolicy.COMPUTED_FULLY_AT_NEW_IMAGE);
try {
pic.setAutofit(true);
pic.writeAll(g, "sample.png");
File file = new File("sample.png");
Image image = new Image(file.toURI().toString());
imageview.setImage(image);
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}