Creating and visualizing graphs - JGraphT(I)

11 February 2008

Graphs are used to represent knowledge in a visual form. There are many types and forms of graphs. Java provides support for graphical structures. In this post, I will talk about JGraphT which is a free Java graph library.

You may download the library from:
http://prdownloads.sourceforge.net/jgrapht/jgrapht-0.7.3.zip?download

Creating and visualizing the graph is very easy:

// create a JGraphT graph
ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class );
 
// create a visualization using JGraph, via the adapter
JGraph jgraph = new JGraph( new JGraphModelAdapter( g ) );

We will use ListenableGraph in our example. ListenableGraph is graph that supports listeners on structural change events. So its flexible. I will start with simple example, and then will introduce other tricky things.

         ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class );
 
        // create a visualization using JGraph, via an adapter
        m_jgAdapter = new JGraphModelAdapter( g );
 
        JGraph jgraph = new JGraph( m_jgAdapter );
 
        adjustDisplaySettings( jgraph );
        getContentPane(  ).add( jgraph );
        resize( DEFAULT_SIZE );
 
        // add some sample data (graph manipulated via JGraphT)
        g.addVertex( "v1" );
        g.addVertex( "v2" );
        g.addVertex( "v3" );
        g.addVertex( "v4" );
 
        g.addEdge( "v1", "v2" );
        g.addEdge( "v2", "v3" );
        g.addEdge( "v3", "v1" );
        g.addEdge( "v4", "v3" );

I just created a ListenableGraph g and added vertexes and edges between those vertexes. So graph is created but no visual effects are added yet.

Do follow the next posts on this very topic.

del.icio.us:Creating and visualizing graphs - JGraphT(I)  digg:Creating and visualizing graphs - JGraphT(I)  spurl:Creating and visualizing graphs - JGraphT(I)  wists:Creating and visualizing graphs - JGraphT(I)  simpy:Creating and visualizing graphs - JGraphT(I)  newsvine:Creating and visualizing graphs - JGraphT(I)  blinklist:Creating and visualizing graphs - JGraphT(I)  furl:Creating and visualizing graphs - JGraphT(I)  reddit:Creating and visualizing graphs - JGraphT(I)  fark:Creating and visualizing graphs - JGraphT(I)  blogmarks:Creating and visualizing graphs - JGraphT(I)  Y!:Creating and visualizing graphs - JGraphT(I)  smarking:Creating and visualizing graphs - JGraphT(I)  magnolia:Creating and visualizing graphs - JGraphT(I)  segnalo:Creating and visualizing graphs - JGraphT(I)  gifttagging:Creating and visualizing graphs - JGraphT(I)

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Creating and visualizing graphs - JGraphT(I)

Leave a Reply