• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

drawing trees

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks stan for the idea, i think that this might work
Omar
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic