• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

drawing trees

 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does a tree have to do with a matrix? And would javax.swing.JTree be good enough?
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks stan for the idea, i think that this might work
Omar
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic