Reputation: 51
I've been trying to display Graph generated with GraphStream in a GUI which is made using JavaFX.Here is what I have so far
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);
The graphViewer is a SwingNode Component.
I think GraphStream doesn't support JavaFX yet, but I'm not sure. Also, I found gs-fx which I don't know how to use.
Any help would be appreciated. If there is some other library like GraphStream to generate the graph and display it in GUI, that would work too.
Upvotes: 3
Views: 1688
Reputation: 1
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();
}
}
Upvotes: 0