Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation is wrong about integrating the viewer into a JPanel + proposed Fix #377

Open
simdeistud opened this issue Dec 8, 2023 · 0 comments

Comments

@simdeistud
Copy link

In the "Graph Visualization" tutorial of the documentation it is said that in order to include the viewer into a user-defined JPanel you have to use more or less the following code:

import org.graphstream.ui.swingViewer.View;
import org.graphstream.ui.swingViewer.Viewer;
// ....
Graph graph = new MultiGraph("embedded");
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
// ...
View view = viewer.addDefaultView(false);   // false indicates "no JFrame".
// ...
myJFrame.add(view);

This unfortunately doesn't work since the View class does not extend JPanel.
The solution I found is instead to use the SwingViewer and the ViewPanel classes, the latter which in fact extends JPanel.

import org.graphstream.ui.swing_viewer.SwingViewer;
import org.graphstream.ui.swing_viewer.ViewPanel;
// ....
Graph graph = new MultiGraph("embedded");
SwingViewer viewer = new SwingViewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
// ...
ViewPanel view = (ViewPanel) viewer.addDefaultView(false);   // false indicates "no JFrame".
// ...
myJFrame.add(view);

This code actually works and correctly embeds a viewer into an external JPanel.

I don't know why the tutorial is wrong since it's supposed to be updated to the 2.0 version of this library.

@simdeistud simdeistud changed the title Documentation is wrong about integrating the viewer into a JPanel Documentation is wrong about integrating the viewer into a JPanel + proposed Fix Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant