I would like to create a JTree from a two dimensional object array that I will import from a SQL query. This is what the SQL table looks like:
Here is sample of the object:
Object[][] table = {
{1, 0, "Root"}, //i=0
{2, 1, "Node2"}, //i=1
{3, 1, "Node3"}, //i=2
{4, 1, "Node4"}, //i=3
{5, 4, "Node5"}, //i=4
{6, 4, "Node6"}, //i=5
{7, 4, "Node7"}, //i=6
{8, 1, "Node8"}, //i=7
{9, 1, "Node9"}, //i=8
{10, 9, "Node10"},}; //i=9
Here is the logic i use to sort the array:
for (int i = 0; i < table.length; i++) {
for (int j = i; j < table.length; j++) {
if (table[i][0] == table[j][1]) {
System.out.println(table[i][2].toString() + " is parent of " + table[j][2].toString());
}
}
}
This is what the above displays in the console:
Root is parent of Node2
Root is parent of Node3
Root is parent of Node4
Root is parent of Node8
Root is parent of Node9
Node4 is parent of Node5
Node4 is parent of Node6
Node4 is parent of Node7
Node9 is parent of Node10
I'm struggling with creating the TreeModel, HashTable, Object, etc. that I can use to create the JTree.
I've been stuck on this problem for over a week and I could really use another person's experience right now.