Unable to refresh the JList

Hi,

I facing the problem which unable to refresh the JList.

I have a splitPane where the first pane is a JTree and the second pane is to display the child of the JTree in JList which user click on.

For the first time the page is view, a list of default child(image, name) is displayed in JList at second pane. After user click on the folder in the JTree, The JList will be update to view the child for the selected tree's child.

The problem is, i was unable to update the JList at all.

Below is part of my code :-

Default JList for the first time the applet is view

childNod =new ChildNod[2];

childNod[0] =new ChildNod("Parent 4","little_bug_red.gif");

childNod[1] =new ChildNod("Parent 5","little_bug_red.gif");

listSelectedTreeChild =new JList(childNod);

listSelectedTreeChild.setCellRenderer(new ListChildRenderer());

JList after user click on the node in JTree

// Declare size for array and add element into ChildNod

childNod =new ChildNod[2];

childNod[0] =new ChildNod("Parent 7","little_bug_red.gif");

childNod[1] =new ChildNod("Parent 8","little_bug_red.gif");

listSelectedTreeChild =new JList(childNod);

listSelectedTreeChild.setCellRenderer(new ListChildRenderer());

listSelectedTreeChild.revalidate();

listSelectedTreeChild.repaint();

i even try to repaint the JSplitPane but it also doesn't work.

Below is the class for ChildNod:

publicclass ChildNod{

private String title;

private String imagePath;

private ImageIcon imageIcon;

public ChildNod(String title, String imagePath){

this.title = title;

this.imagePath = imagePath;

}

public String getTitle(){

return this.title;

}

public ImageIcon getImage(){

if (imagePath !=null){

imageIcon =new ImageIcon(imagePath);

}

return imageIcon;

}

public String toString(){

return title;

}

}

I had search through the forum, and i had try by using the "DefaultListModel" but it still doesn't work.

[3508 byte] By [spch2oa] at [2007-11-27 8:48:48]
# 1

> listSelectedTreeChild = new JList(childNod);

Creating a new JList does not add the list to the GUI. It just creates a JLIst object in memory. You need to add the list to the split pane.

However, the easier approach is to just reset the model of the list:

ListModel model = ....

list.setModel( model );

That it. No need for a revalidate() or repaint(). Not sure if you need to reset the renderer or not.

camickra at 2007-7-12 20:56:40 > top of Java-index,Desktop,Core GUI APIs...