Creating and visualizing graphs - JGraphT(I)
11 February 2008Graphs 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.
Related Posts:
- Creating JAR files - 2
- Creating MessageDigest - 2
- Java built-in data types (performance issues)
- RecordStore with examples - I
- Creating JAR files
- Eclipse - Creating path variables
- Creating a Thread (implementing Java Runnable Interface)
- Creating a Simple Plug-in using PDE (II)
- Creating a plug-in project (I)
- Creating MessageDigest - 1
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)