Search code examples
javaswingimageicon

Autoresize the image using imageicon on jlabel


I need to fit the image on jlabel, my images are stored in MySql table and I getting those using following code -

byte[] imagedata=rs.getBytes(6); // rs is ResultSet of table
format=new ImageIcon(imagedata);
jLabel15.setIcon(format);

How can I resize the "format" which I want to display on jLabel15.

Edited: Image column in table is bigblob data type


Solution

  • you can scale your image the following way,

        Image img = format.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH);
        jLabel15.setIcon(new ImageIcon(img));
    

    I have scalled the image to 50X50 you can scale it to your desired size