This has been asked a million times it appears, but I must be feeling especially dense tonight because I’m still having trouble. My first question is this, when I call
ImageIcon icon = new ImageIcon(getClass().getResource("images/x.jpg"));
where is it looking for the images folder? I’ve tried making it a folder under my project and under src. What am I missing? I’m using Eclipse. As you’ve probably guessed already, I haven’t done much Java.
What I really want to do is to set the the first column in a table to an initial icon and then allow the user to double click on it and change the icon. Could someone be so kind as to gently push (or violently shove) me in the right direction? Do I need my own renderer class?
class MyRenderer extends DefaultTableCellRenderer {
....
When someone double clicks on the row I want to change the icon to y.jpg.
Edited
Thanks for the help. Another dumb question. Should I see the icon when I add a row like this?
DefaultTableModel dm = (DefaultTableModel)tblNews.getModel();
ImageIcon icon = new ImageIcon(getClass().getResource("/x.jpg"));
dm.addRow(new Object[]{icon, "Text"});
I see the filename of the icon, but not the icon itself.
1) your ImageIcon could be placed for
(
new ImageIcon(getClass().getResource("images/x.jpg"));)src
MyPackage
MyPackage/images
more Packaging in Java
2) JTable knows Icon / ImageIcon as Object, then there no reason set for Icon in the Renderer