0

I'm trying to show image in a Jable, but whenever I try, it shows the image path, for example: sun.awt.image.ToolkitImage@14258d93, sun.awt.image.ToolkitImage@41b7f519, sun.awt.image.ToolkitImage @ 36a94c02 ... instead of showing an image ... someone please solve this problem, because I've been trying to find a solution for hours ...

code:

        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")
            });
        }

Note: I already managed to apply this image to a JLabel using (JLabelName) .setIcon (icon);

Thiago Viana
  • 301
  • 2
  • 9
  • See https://stackoverflow.com/questions/4941372/how-to-insert-image-into-jtable-cell – jjaazz Aug 03 '18 at 17:21
  • `I've been trying to find a solution for hours` - did you try searching with keywords like "ImageIcon JTable"? If you want to know how to do something then use the class names of the objects involved to do your search. – camickr Aug 03 '18 at 17:27
  • does this mean that I can not insert image after the Jtable is rendered? – Thiago Viana Aug 03 '18 at 17:28
  • 1
    Try it and see what happens. There is complete code for you to download and test. How hard can it be to modify the code for your requirement? – camickr Aug 03 '18 at 17:28
  • @camickr It's difficult because I use Code Generated, NetBeans does not allow editing. then it is automatically generated without the photo, the other topic shows the creator of the table already with the image. look : http://prntscr.com/ked447 Do you have a solution? – Thiago Viana Aug 03 '18 at 17:58
  • 1
    Don't use NetBeans to generate your code. Learn how to write Java/Swing code, not how to use an IDE. – camickr Aug 03 '18 at 20:42

0 Answers0