我一直试图在使用JavaFX制作的GUI中显示与GraphStream生成的图形。这是我到目前为止写的
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();
}
}