This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable Cell Rendere Not showing Icons properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Cell Rendere Not showing Icons properly" Watch "JTable Cell Rendere Not showing Icons properly" New topic

JTable Cell Rendere Not showing Icons properly

Muhammad Asghar

Joined: Mar 15, 2011
Posts: 6

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);
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();

for(int i=0;i<vList.size(); i++){
Vector v= new Vector();
tblMainView.getColumnModel().getColumn(0).setCellRenderer(new KeyIconCellRenderer(metaData.getClientpath()));
v.add(new Date(metaData.getTime()));
v.add("Pending Upload");

dtModel.insertRow(0, v);


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,

[Thumbnail for attachment.PNG]

Darryl Burke

Joined: May 03, 2008
Posts: 5092

Hi Muhammad, please BeForthrightWhenCrossPostingToOtherSites

luck, db
There are no new questions, but there may be new answers.
subject: JTable Cell Rendere Not showing Icons properly
It's not a secret anymore!