File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes help with itteration through a multi dimensional array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "help with itteration through a multi dimensional array?" Watch "help with itteration through a multi dimensional array?" New topic

help with itteration through a multi dimensional array?

krillian konstatos
Ranch Hand

Joined: Jan 03, 2011
Posts: 49

Good evening, all!

I have encountered a tricky problem for me in a project where i wan't to populate a JTree component object
with nodes which are constructed from a multidimensional array of tree data objects. Theese nodes are
inserted into my treemodel with the insertNodeInto(DefaultMutableTreeNode node, DefaultMutableTreeNode parent,
int index) method in the DefaultTreeModel class.

Below i have posted the following example of my TreeData class that i want to use in my tree nodes as a user object

The TreeData class in the above piece of code controls the layout in a JPanel object in my project's main class.
Anyway its not important for this post what this object does. As I said earlier I want to populate a JTree from TreeData objects
that reside within a multidiemensional array. The TreeData object that takes only one String object as a parameter in it's constructor
is user objects attached to the parent nodes in my JTree.

Below i have a piece of code that demonstrated how i wish to accomplish this attempt i could use another approach i am thinking of
doing this using xml parsing instead but for now i need some hint on how to populate the jtree object correctly so that the nodes will be
inserted into model in the correct order so far my node insertion attempts have only resulted in reversed order i am not good at
using the collection classes in java but i know the solution to this problem is there somewhere ...

Below theese lines are an example of what i have tried so far to populate my JTree object from a multi diemensional.
The code below only results in the fact that the nodes in my JTree appears in a reversed order.

How can i use the Set<Object> class or the ListIterator<Object> class
to iterate through my arrays of TreeData and insert them into a treemodel in the correct order and in a way similar to the one in the code example above this line?
I have only used collection classes with a single array of objects as a generic parameter. I hope i have been clear enough in the description of my problem in
question. I would really appreciate any kind of hint or help here and thanks a lot for your visit here.

im a collection "camper".
krillian konstatos
Ranch Hand

Joined: Jan 03, 2011
Posts: 49

this case is solved for now, anyway i have manage to get it to work as i have imagined at first i have modified the
method below this line in the following way ...

If someone have second thoughts to my solution or other opinions to it please feel free to
write them down here. Thanks a lot to all who have visited this post.

I agree. Here's the link:
subject: help with itteration through a multi dimensional array?
It's not a secret anymore!