我一直在尝试显示使用 GraphStream 生成的图表在使用 JavaFX 制作的 GUI 中。这是我到目前为止所拥有的
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 中显示它,那也可以。
最佳答案
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();
}
}
关于java - 如何在 JavaFX GUI 组件中显示使用 graphstream 生成的图形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31760706/