Skip to content

Instantly share code, notes, and snippets.

@myro
Created June 30, 2012 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myro/31e57aa84473c0887d2a to your computer and use it in GitHub Desktop.
Save myro/31e57aa84473c0887d2a to your computer and use it in GitHub Desktop.
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.MultiGraph;
import org.graphstream.ui.swingViewer.Viewer;
public class AllInSwing
{
public static void main(String args[])
{
new AllInSwing();
}
public AllInSwing()
{
Graph graph = new MultiGraph("mg");
Viewer viewer = new Viewer(graph,
Viewer.ThreadingModel.GRAPH_IN_SWING_THREAD);
SwingUtilities.invokeLater(new InitializeApplication(viewer, graph));
}
}
class InitializeApplication extends JFrame implements Runnable
{
private static final long serialVersionUID = -804177406404724792L;
protected Graph graph;
protected Viewer viewer;
public InitializeApplication(Viewer viewer, Graph graph)
{
this.viewer = viewer;
this.graph = graph;
}
public void run()
{
viewer.enableAutoLayout();
viewer.disableAutoLayout();
viewer.enableAutoLayout();
viewer.disableAutoLayout();
viewer.enableAutoLayout();
viewer.disableAutoLayout();
viewer.enableAutoLayout();
add(viewer.addDefaultView(false), BorderLayout.CENTER);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(800, 600);
setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment