I have a panel which contains JList.
When i add this panel to west BorderLayout with one element everything is OK and i see one element in it but if i add new element or clear all element i see no effect.
Can any body suggest any solution?
JPanel class which contains JList
public class FtpPanel extends JPanel{
public JList ftpJList;
public DefaultListModel ftpListModel;
public FtpPanel(String[] list) {
this.setLayout(new BorderLayout());
this.setBorder(new EmptyBorder(20, 20, 20, 20));
this.ftpListModel = new DefaultListModel();
for(String s : list){
this.ftpListModel.addElement(s);
}
this.ftpJList = new JList(ftpListModel);
final JScrollPane wsp = new JScrollPane(this.ftpJList);
wsp.setBorder(new TitledBorder(new WebBorder(),"ftpsrv.itra.de"));
this.add(wsp, BorderLayout.CENTER);
}
}
FtpTabPanel to which FtpPanel will be added
public class FtpTabPanel extends JPanel{
public FtpPanel ftpPanel;
public FtpTabPanel() {
createComponents();
layoutComponents();
initializeComponents();
}
private void createComponents() {
ftpPanel = new FtpPanel(new String[]{"You aren't Connected"});
}
private void layoutComponents() {
setLayout(new BorderLayout());
add(ftpPanel, BorderLayout.WEST);
}
}
Add and remove from Jlist
addFileToJlist(listOfFtpFile ){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if(listOfFtpFile !=null)
ftpTabPanel.ftpPanel.ftpListModel.clear();
ftpTabPanel.ftpPanel.updateUI();
for(String s : listOfFtpFile){
ftpTabPanel.ftpPanel.ftpListModel.addElement(s);
ftpTabPanel.ftpPanel.ftpWebList.validate();
ftpTabPanel.ftpPanel.updateUI();
}
ftpTabPanel.ftpPanel.ftpWebList.revalidate();
panel.updateUI();
}
});
}
Here is a simple working example (that is almost same as yours but without unnecessary updates):
And i don’t really see any problems in your example (except unnecessary validation and updateUI calls). Seems that problem is somewhere else…