0

I have a connection with a MySQL database, and I try to resolve a issue which appear when the blob (image) extracted from database don't render correctly into a JDialog (see screenshot). Note: I have multiple images (size ~50-60 Kb), some of them appear correctly (full), but some of them appear not-fully loaded. I tried to re-save and insert the image into MySQL, but the issue persist.

enter image description here

Any ideas?

My code is:

MenuItemPhoto.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {

                    try {
                        String sql = "select photo from RDSSPhoto where id ='38'";
                        pst = conn.prepareStatement(sql);
                        rs = pst.executeQuery();

                        if (rs.next()) {

                            byte[] imagedata = rs.getBytes("photo");
                            format = new ImageIcon(imagedata);
                            JOptionPane pane = new JOptionPane((Frame) null, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION);

                            JDialog d = pane.createDialog((Frame) null, "Photo");

                            pane.setIcon(format);
                            if (!d.isVisible()) {
                                d.setLocationRelativeTo(RDSSView.this);
                                d.pack();
                            }

                            d.setVisible(true);

                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }

        });

2 Answers2

0

That's crazy. I never seen it before. Looks like the Dialog needs the refresh/repaint or some like that.

You can try this:

SwingUtilities.invokeLater(new Runnable()
{
   public void run() {
      d.pack();
   }     
}
matheuslf
  • 309
  • 1
  • 9
0

After a perfect cup of coffee, I found the problem of my issue. The MySQL column where the images are stored was set to BLOB, which means that every row can store maximum 65535 bytes (~ max 64 Kb). After I changed that column into LONGBLOB, the issue persist. But after I inserted again my images in database, the JDialog looks great.

So the problems was from the column type.