JGraphx has a nice example called editor that does exactly what you are trying to accomplish. Just look in the downloaded zip file in the /examples/com/mxgraph/examples/swing/editor - there is everything you need.
Alternatively you might want to use JUNG http://jung.sourceforge.net/. For this one see the following demo - it might give you some clues: http://jung.sourceforge.net/applet/grapheditordemo.html