データベースの結果セットに基づいて JTree を生成しようとしています。私は得る
Category | Name
-------- | ----
A | 1
B | 2
A | 3
データベースから。必要な場合にのみカテゴリを JTree に追加するにはどうすればよいですか? ツリーを次のようにしたいと思います。
[Root]
[Category A]
Child 1
Child 3
[Category B]
Child 2
これは私がこれまでに持っているものです:
//Get the blueprints
SqlHelper shelp = new SqlHelper();
ArrayList<BaseInformation> bpList = shelp.getBlueprints();
//Add each to model
for(int x = 0; x < bpList.size(); x++){
BaseInformation info = bpList.get(x);
category = new DefaultMutableTreeNode(info.blueprintCategory);
top.add(category);
category.add(new DefaultMutableTreeNode(info.blueprintName));
}
JTree tree = new JTree(top);
TreeModel model = tree.getModel();
return model;