0

I have objects that build a graph. Each object is a node of the graph and represented by an JInternalFrame in the JDesktopPane. Now I want to layout the Frames correspondig to the graph. Diplaying the edges is not my problem, but to get proper positions for each Frame(Node).

Have you an advice for a good aproach for this? I tried already to build an graph with the JUNG library, let JUNG calculate positions of nodes and transfere them to my swing components. But I am not satisfied with the solution as there result is kind of random.

br Tobias

tobi
  • 753
  • 1
  • 14
  • 25
  • What are the rules for node positioning? – MadProgrammer Jun 26 '14 at 21:11
  • Thats a good question. Basically there are some nodes that should be positioned left and everything connected to them should be directed from left to right. However, currently I have no clue, how to define such rules (using JUNG) – tobi Jun 28 '14 at 06:39

1 Answers1

0

I can understand your pain here . I also do the same . ie. in my java application i take various inputs and combine it to produce a graph . The challenge remains to output the graph on the screen so that it can be meaningfully understood by the user of the application . My graphs can be extremely big . Here is what i do :

1 . I use Graphiz dot library to generate my graph . In case you are unfamiliar with Graphiz, it is a very popular graph layouting tool . It essentially does the same thing as the JUNG library . But since i have never used JUNG i will not speak about it . The Graphiz dot engine computes the position of the vertex and edges for you .

2 . I have created a Graphical editor that can parse the (x,y) co-ordinates specified in the .dot file( output file generated by Graphiz ) and show on the screen . Only the parsing part is tricky as the editor takes care of most of the visualization aspects ( like zooming , drag and drop edges and vertex , etc ) . You can check out the editor here Jgraphx . Download their source code and have a look at the GraphEditor example . Run that example and see . Let me know if you want me any more help .

I think you have achieved 1 and you need to achieve 2 . Hope my answer helps.

rockstar
  • 3,512
  • 6
  • 40
  • 63
  • have to overrride getPreferredSize for APIs based on Swings containers – mKorbel Jun 27 '14 at 07:58
  • I took a look at JGraphx and I like it very much. However I was not able to find a good documentation. I need only to layout a graph, here is a first try to get the positions of the nodes. But it's throwing a NullPointerException. Do you have an example for applying a layout and receiving the positions? – tobi Jun 28 '14 at 21:24
  • @tobi I see your comment to madprogrammer . Well if you wanna arrange the nodes from left to right then allow the graphiz to do it . As you can you cannot get it going using JUNG . – rockstar Jun 30 '14 at 01:45
  • @tobi Here is a very small example . http://www.graphviz.org/content/arrange-nodes-left-right-my-own-order . Another slightly bigger example : http://stackoverflow.com/questions/14123259/how-to-enforce-the-left-to-right-node-ordering-in-graphviz-rank-layout . These should make you comfortable creating your own dot file . Once you have the dot file you can generate the layout graph easily . – rockstar Jun 30 '14 at 01:47