3

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.

nirajftw
  • 51
  • 5

1 Answers1

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();
    }
}
  • 1
    While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read [_How do I write a good answer_](https://stackoverflow.com/help/how-to-answer) to know more. – Roshana Pitigala Sep 22 '18 at 11:40