在Jtable上插入ImageIcon,仅显示图像路径

时间:2018-08-03 17:18:08

标签: java swing jtable imageicon defaulttablemodel

我试图在Jable中显示图像,但是每当尝试显示图像路径时,它就会显示图像路径,例如:sun.awt.image.ToolkitImage @ 14258d93,sun.awt.image.ToolkitImage @ 41b7f519,sun。 awt.image.ToolkitImage @ 36a94c02 ...而不是显示图像...有人请解决此问题,因为我一直在努力寻找解决方法……

代码:

        DefaultTableModel table = (DefaultTableModel) tabelinha.getModel();
        table.setNumRows(0);
        while(dados.next()){
            byte[] picture = dados.getBytes("Foto"); // get image off DB
            ImageIcon icon = new ImageIcon(picture); //create image icon
            table.addRow(new Object[]{ //add new row on Jtable
                dados.getInt("Id"),
                dados.getString("Nome"),
                dados.getString("Nome"),
                icon.getImage(), // error here, dont show image, only image PATH
                dados.getString("Rg"),
                dados.getString("Cpf"),
                dados.getString("Cep"),
                dados.getString("Modalidade"),
                dados.getString("Horario"),
                dados.getString("Frequencia"),
                dados.getString("Professor")
            });
        }

注意:我已经设法使用(JLabelName).setIcon(图标)将此图像应用于JLabel;

0 个答案:

没有答案