- From: <georgevio AT gmail.com>
- To: graphstream-users AT litislab.fr
- Subject: graphstream embedded in JavaFX
- Date: Thu, 19 Dec 2019 07:07:06 +0100 (CET)
I created a minimal JavaFX project with both empty Controller and fxml file.
The Application file is below. The first group of lines is a normal
graphstream
graph which shows ok on a SEPARATE window. The next two groups are trying to
show it inside the javafx window.
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.ui.swingViewer.GraphRenderer;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
Graph graph = new SingleGraph("Graph");
graph.addNode("1"); graph.addNode("2"); graph.addNode("3");
graph.addEdge("1-->2","1","2", true);
graph.addEdge("1-->3","1","3", true);
/* These 3 lines show correctly a graph, ON A SEPARATE WINDOW */
Viewer viewer = new Viewer(graph,
Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
viewer = graph.display(true);
viewer.enableAutoLayout();
// Those below both do not work. I tried many vestions of gs-ui-javafx
but ...
//
https://github.com/graphstream/gs-ui-javafx/blob/master/src-test/org/graphstream/ui/viewer_fx/test/AllFxTest.java
FxViewer fxviewer = new FxViewer(graph,
FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
FxGraphRenderer renderer = new FxGraphRenderer();
FxDefaultView view = (FxDefaultView)
fxviewer.addView(FxViewer.DEFAULT_VIEW_ID, renderer);
/*
https://github.com/graphstream/gs-ui-javafx/blob/master/src-test/org/graphstream/ui/viewer_fx/test/AllFxTest.java
*/
FxViewer v = new FxViewer(graph,
FxViewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
v.enableAutoLayout();
FxViewPanel panel = (FxViewPanel)v.addDefaultView(false, new
GraphRenderer());
Scene scene2 = new Scene(panel, 800, 600);
primaryStage.setScene(scene2);
}
public static void main(String[] args) {
launch(args);
}
}
- graphstream embedded in JavaFX, georgevio, 19/12/2019
Archives gérées par MHonArc 2.6.16.