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);
}