Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable Cell Rendere Not showing Icons properly

 
Muhammad Asghar
Greenhorn
Posts: 6
Firefox Browser Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
attachment.PNG
[Thumbnail for attachment.PNG]
Snapshot of the issue,
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Muhammad, please BeForthrightWhenCrossPostingToOtherSites
http://stackoverflow.com/questions/5456721/java-jtable-not-showing-icons-properly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic