Panel won't update

publicclass TermPanelextends JPanel

{

private CourseStorer courseStorer =null;

private Course currentCourse =null;

private JComboBox allCourses =null;

private ArrayList<Author> authorsOfCourse =null;

private JPanel AUTHOR_PANEL =null;

/**

* Construct a TermPanel object.

* @param courseStorer An object containing

* information about all course and authors

* in the database, along with their respective

* questions.

*/

public TermPanel(CourseStorer courseStorer)

{

this.courseStorer = courseStorer;

this.currentCourse = courseStorer.getCourses().get(0);

setBackground(Color.white);

setPreferredSize(new Dimension(600, 600));

setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

// Initialize the Authors ArrayList

authorsOfCourse = currentCourse.getAuthors();

// Add all the courses to the JComboBox as well as the actionListener.

allCourses =new JComboBox();

allCourses.addItemListener(new CourseComboBoxListener());

for (int i = 0; i < courseStorer.getCourses().size(); i++)

allCourses.addItem(courseStorer.getCourses().get(i));

JPanel coursePanel =new JPanel();

coursePanel.setBackground(Color.white);

coursePanel.add(new JLabel("Course Name: "));

coursePanel.add(allCourses);

AUTHOR_PANEL =new JPanel();

AUTHOR_PANEL.setBackground(Color.white);

AUTHOR_PANEL.setLayout(new GridLayout(0,1));

add(coursePanel);

add(AUTHOR_PANEL);

}

privatevoid updateGUI()

{

AUTHOR_PANEL.removeAll();

for (int i = 0; i < authorsOfCourse.size(); i++)

{

Author author = authorsOfCourse.get(i);

JPanel temp =new JPanel();

temp.setBackground(Color.white);

temp.add(new JLabel(author.getName()));

temp.add(new JLabel("Easy " + author.getNumOfEasyQ()));

temp.add(new JLabel("Medium " + author.getNumOfMedQ()));

temp.add(new JLabel("Hard " + author.getNumOfDiffQ()));

temp.add(numOfQuestions[i]);

AUTHOR_PANEL.add(temp);

}

}

privateclass CourseComboBoxListenerimplements ItemListener

{

publicvoid itemStateChanged(ItemEvent ie)

{

Course myCourse = (Course) allCourses.getSelectedItem();

authorsOfCourse = myCourse.getAuthors();

updateGUI();

}

}

}

The problem is that when ever I click on the drop down menu, the AUTHOR_PANEL

remains the same, it never changes like it is suppose to.

After debugging I figured out that updateGUI() is being entered, but the changes aren't begin reflected on the actual GUI for some reason.

Any help would be greatly appreciated.

Thank you.

[4600 byte] By [java4life87a] at [2007-11-27 8:08:58]
# 1

After calling:

AUTHOR_PANEL.removeAll();

Make sure you reset your layout manager on that panel, then re-add the components, then add it back to the parent panel.

Then make a call to invalidate() on the parent panel. That should tell the components and it's children to redraw themselves.

bryanoa at 2007-7-12 19:52:00 > top of Java-index,Desktop,Core GUI APIs...
# 2
If you add / remove component to / from a panel in a visible GUI then you need to revalidate() the panel.
camickra at 2007-7-12 19:52:00 > top of Java-index,Desktop,Core GUI APIs...
# 3
Oops, wrong thread...Message was edited by: camickr
camickra at 2007-7-12 19:52:00 > top of Java-index,Desktop,Core GUI APIs...
# 4
I used revalidate and it worked perfectly. Thank you.For the record, what is a source that will teach me good swing?Message was edited by: java4life87
java4life87a at 2007-7-12 19:52:00 > top of Java-index,Desktop,Core GUI APIs...