I have a slight problem when trying to display an image on inside a cell in JTable
, this takes a text format and shows the image itself.
E.G. icon.toString()
" returns:
My code:
public void loading() {
try {
String[]title = {"First Name","Last Name","Picture"};
String sql="select * from users";
model = new DefaultTableModel(null,title);
st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
String[]fila = new String[4];
while(rs.next()){
fila[0] = rs.getString("fna");
fila[1] = rs.getString("lna");
byte[] imgBytes = rs.getBytes("pic");
Blob blob = new javax.sql.rowset.serial.SerialBlob(imgBytes);
BufferedImage image = null;
try (InputStream is = blob.getBinaryStream()) {
image = ImageIO.read(is);
ImageIcon icon = new ImageIcon(image);
fila[2] = icon.toString();
} catch (IOException exp) {
exp.printStackTrace();
}
model.addRow(fila);
}
tbl.setModel(model);
}
catch (SQLException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
Anyone knows how the code can be corrected?