JTree - Issues with adding of nodes
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-23T11:38:20Z
Indexed on
2010/05/23
11:40 UTC
Read the original article
Hit count: 298
Hi. Im developing a system that stores courses that participants can apply to. I'm presenting the enrollments in a JTree in the courseadministratorGUI.
My problem is that, for every enrollment it's adding a new courseNode.
Been trying for many hours, and hope I can now get some advice that will point me in the correct direction. Thank you.
private void updateJTree() {
for (Category cat : catcontrol.getAllCategoriesList()) {
category = new DefaultMutableTreeNode(cat);
for (Course c : ccontrol.getAllCourses()) {
if (cat.getIdCategory() == c.getIdCategory()) {
for (Enrollment e : econtrol.getAllEnrollments()) {
if (e.getIdCourse() == c.getIdCourse()) {
if (cat.getIdCategory() == c.getIdCategory() && e.getCourse().equals(c)) {
root.add(category);
}
if (c.getIdCourse() == e.getIdCourse()) {
course = new DefaultMutableTreeNode(c);
category.add(course);
enrollment = new DefaultMutableTreeNode(e.getParticipant().getFirstNames());
course.add(enrollment);
}
}
}
}
}
}
jTree1.setModel(new DefaultTreeModel(root));
jTree1.addTreeSelectionListener(this);
jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}
© Stack Overflow or respective owner