aspose file tools*
The moose likes Java in General and the fly likes drawing trees Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "drawing trees" Watch "drawing trees" New topic
Author

drawing trees

omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
hi, sorry for this is a general programming question.
i need to draw a tree.
i have a 10*10 matrix, those are 100 cube, and i get to change the text that exists in this cube,
the problem is that i still dont know how to draw the tree, is there an algorithm that i can read and implement, any idea or a link would be appreciated.
thanks for any help
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
What does a tree have to do with a matrix? And would javax.swing.JTree be good enough?


There is no emoticon for what I am feeling!
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
sorry, but im creating and drawing my own tree, it a combination of graphical objects that i place on the stage, and i can change there colors. the stage is like a 10*10 matrix.
the tree data are saved in an array. i only need an idea on how to show the tree on the stage..
thanks
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
To begin with, you should be familiar with at least parts of the Java 2D API:
http://java.sun.com/docs/books/tutorial/2d/index.html
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Ah, that makes more sense. The "trees" in this page are actually HTML tables with some graphics in the right cells. Does that sound like what you're trying to do in Swing? If so, you can surely make yours look better than mine.

Is your challenge how to get images on the screen or how to decide which images go in which cell?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
hey guys
i need to know which images go in which cell
that is my problem, i just need an idea..

thanks and happy new year
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
So we're talking something like:

I don't know how your data is stored, but you might have a recursive routine that walks through the tree and calls a tree-renderer for each node. I'd pass an argument along to keep track of the call depth so I'd know how far to indent each line. Knowing what kind of line graphics to run down the left is trickier. You can see I didn't do a very neat job on that HTML example. I just put an elbow shaped like an L for each sub-folder. You might want a T shape (turned counter-clockwise) for something that has a child and a sibling.

How is your data stored? Are you comfortable with recursion?
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
thanks stan for the idea, i think that this might work
Omar
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: drawing trees