1

Here is my code to display full image in a jlable

FileDialog fd=new FileDialog(this);
        fd.show();
        picturepath=fd.getDirectory()+fd.getFile();
        jLabelPictureAdd.setIcon(new ImageIcon(picturepath));
        jLabelPictureAdd.setHorizontalAlignment(jLabelPictureAdd.CENTER);

diplays only part of the image

but it dosen't display the full image but part of the image please someone help me to sort this out. thank you

silent9
  • 25
  • 4
  • 1
    Possible duplicate of [Resize a picture to fit a JLabel](http://stackoverflow.com/questions/16343098/resize-a-picture-to-fit-a-jlabel) – TimeToCode Sep 20 '16 at 14:29
  • Dimensions of image maybe too big for the JLabel...So its either you resize the Label or the image. – Young Emil Sep 20 '16 at 14:31

2 Answers2

0

You may need to make your image a smaller resolution, or give your label larger bounds.

It's pretty tricky and I mostly just figured it out after several trial-error attempts. For starters, try setBounds() to set the aspect ratio of the label to be the same as the image. Your image will not be shrunk down to fit into the label, similar to how when you select "Fill" when changing your Windows wallpaper.

jseashell
  • 745
  • 9
  • 19
0
jLabelPictureAdd.setIcon(new ImageIcon(new ImageIcon(picturepath).getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT)));
Young Emil
  • 2,220
  • 2
  • 26
  • 37