views:

138

answers:

7

I want to draw graphs (nodes and edges) in Java. However, since I don't know how to go about it, I would like to have some advice before starting.

How should I do this?

use Graphics2D package, right?

How about the labels for the nodes? should I use something like drawString and handle all the "centering" manually or create a JLabel for that? Can I put a JLabel on a Graphics2D environment?

I have searched but haven't found any simple implementation of this. If you know of one, please provide the link in your answer.

edit: The solution I am looking for should be able to remove nodes, drag nodes, edit labels, create nodes, all with mouse events.

Thanks.

+4  A: 

Perhaps this will help: JUNG.

And you will probably need to read this: http://jung.sourceforge.net/doc/JUNGVisualizationGuide.html

Moron
A: 

I would suggest grappa. http://www.research.att.com/~john/Grappa/grappa.tgz

svlada
A: 

JGraphT and JGraph are another option. JGraph is used for rendering graphs in the GUI and handling user interaction while JGraphT is the underlying graph model, data structures and algorithms.

dano82
+1  A: 

If you want to do it yourself the GraphLayout examples will help.

This is a good example with only a few lines of code.

If you want to use a more sophisticated framwork check JGraph

stacker
+1  A: 

"Graph Panel is a simple example of an object drawing program."

trashgod
A: 

There are lots of choices. The GVSR Project maintains a list. You can limit your search to Java libraries only.

Martin Harrigan
+1  A: 

Also check out jGo at http://www.nwoods.com/go/jgo.htm

Fuzzy