0

I am trying to create a graph using the GraphStream API. I want to add some visual effects on top of the graph Layout drawn with the API, so I plan to embed the graph in a JFrame.

I read this post here (How to draw graph inside swing with GraphStream actually?), to look some implementations, but I am always getting an exception error:

Exception in thread "AWT-EventQueue-0" java.lang.VerifyError: (class: org/graphstream/ui/swingViewer/Viewer, method: addDefaultView signature: (Z)Lorg/graphstream/ui/swingViewer/View;) Incompatible argument to function
at ShowGraph$MyFrame.<init>(ShowGraph.java:17)
at ShowGraph$1.run(ShowGraph.java:34)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

The code used is the same as the one in the link:

public class ShowGraph

{

private static Graph graph = new SingleGraph("Graph");

public static class MyFrame extends JFrame
{
    private static final long serialversionUID = 8394236698316485656L;
    private Viewer viewer = new Viewer(graph,Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
    private View view = viewer.addDefaultView(false);

    public MyFrame()
    {
        setLayout(new BorderLayout());
        add(view,BorderLayout.CENTER);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
}

public static void main(String args[])
{
    SwingUtilities.invokeLater(new Runnable() 
    {

        public void run() {

            graph.addNode("A");
            graph.addNode("B");
            graph.addNode("C");
            graph.addEdge("AB", "A", "B");
            graph.addEdge("BC", "B", "C");
            graph.addEdge("CA", "C", "A");

            MyFrame frame = new MyFrame();
            frame.setSize(320, 240);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);

        }
    });
}

}

Community
  • 1
  • 1
  • Can you provide the code where you are calling `Viewer.addDefaultView(...)` ? – zer0chain May 25 '16 at 21:36
  • I've edited the post. – Hugo Gayoso May 27 '16 at 18:11
  • It seems you are using an old version of GraphStream since viewer and view are now in the `org.graphstream.ui.view` package. Can you confirm ? – zer0chain Jun 01 '16 at 13:03
  • I am using the version 1.3. Also, I've included their last night built. – Hugo Gayoso Jun 02 '16 at 14:45
  • Hey, It seems that I have to cast the view object when I am adding to the JFrame. I added `add((Component)view,BorderLayout.CENTER);` and its working now. Do you know why I have to do this? Thanks! – Hugo Gayoso Jun 02 '16 at 14:51
  • Yes. You have to do this become we (GraphStream Team) are trying to made the UI generic, so it will not be linked to Swing. The goal is to let the user the choice in the ui engine. So the View does not extend directly any Swing or AWT component, and so you have to cast it to tell the compiler what you are trying to do. – zer0chain Jun 03 '16 at 07:59

0 Answers0