Hi All,
in my application i need to display file system files in JTable, when i click on the JTree node which is any system folder, the contents of that folder are shown in the JTable,
In the first column of the Jtable, with the name of the file or folder icon is shown, the icon is fetched from the system icon and is displayed.
Every thing is working fine the problem is that, when renderer renders icon, the icon of the first file(first row of Jtable) is repeated in all, i mean the icon does not change in the subsequent rows of the JTable, here my code is in which a render gets icon and the model displays it in the JTable
/////
class KeyIconCellRenderer extends DefaultTableCellRenderer {
public KeyIconCellRenderer(
String ext) {
File file = new File(ext);
Icon icon = FileSystemView.getFileSystemView().getSystemIcon(file);
setIcon(icon);
}
}
//////
and here is code where i am using rendrer to display
///
private class Selection implements TreeSelectionListener {
public void valueChanged(TreeSelectionEvent e) {
Object[] myData= new Object[6];
TreePath path = e.getPath();
FileUtil util= new FileUtil();
FileMetaData metaData;
Vector<FileMetaData> vList = new Vector<FileMetaData>();
DefaultMutableTreeNode node = (DefaultMutableTreeNode)treeMainView.getLastSelectedPathComponent();
FileInfo info =(FileInfo)node.getUserObject();
File filePath= info.getFilepath();
vList=util.getChildList(filePath);
dtModel.getDataVector().removeAllElements();
for(int i=0;i<vList.size(); i++){
Vector v= new Vector();
metaData=(FileMetaData)vList.get(i);
v.add(metaData.getName());
tblMainView.getColumnModel().getColumn(0).setCellRenderer(new KeyIconCellRenderer(metaData.getClientpath()));
v.add(metaData.getClientpath());
if(metaData.isDirectory()){
v.add("");
}else
{
v.add((FileHelper.getSizeString(metaData.getSize())));
}
if(metaData.isDirectory()){
v.add("");
}else
{
v.add(new Date(metaData.getTime()));
}
if(metaData.isDirectory()){
v.add("Folder");
}else
{
v.add("File");
}
v.add("Pending Upload");
dtModel.insertRow(0, v);
}
tblMainView.repaint();
}
}
///
as in the attached image, only the icon of the fist file is repeated in all rows,
Please help, it will be a huge favor,
Thanks