0

in my code i need to set a icon in a table but just see the url of icon in cell

public void listread(){
    ImageIcon hpi = new ImageIcon("D:\\workspace\\1.ico");
    connectionQuery();
    try{
        Statement stm = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rss = stm.executeQuery("SELECT idusers, username, usertype, userpass FROM maindb.users");
        while(rss.next()){
            idusers = rss.getInt("idUsers");
            username = rss.getString("username");
            userval = rss.getInt("usertype");
            userpass = rss.getInt("userpass");
            if(userpass > 0){
                model.addRow(new Object[]{idusers, username, userval, hpi.getImage()});
            }else{
                model.addRow(new Object[]{idusers, username, userval}); 
            }

            System.out.println(String.format("%s - %s - %s - %s", idusers, username, userval, userpass));
        }
        con.close();
    }catch(Exception e1){
        System.out.println(e1);
    }
}

so hpi is my icon and if use it return icon physical url(D:\workspace\1.ico) and if use hpi.getimage() then return memory url(sun.awt.image.ToolkitImage@20b62cf9) of icon

  • 2
    You need to set a correct renderer for the Icon column: http://stackoverflow.com/questions/23560063/how-to-render-an-image-to-a-jtable-cell – david a. Nov 01 '16 at 12:30
  • david a.'s link already contains all you need to know, so I post this here as a complete example for you to test with: http://stackoverflow.com/a/5615516/1368690 – hamena314 Nov 01 '16 at 15:23

0 Answers0