2

Hello I am setting image to JLabel as below

ImageIcon icon=new ImageIcon(PathToImage,"Image");
jLabel4.setIcon(icon);

I have set label size as 5cm x5 cm square. Whenever i am setting icon to Jlabel it is not shown fully .. only part of image is shown in jlabel. How to solve this ?

Thanks !

Sachin Doiphode
  • 431
  • 2
  • 10
  • 24

3 Answers3

2

Increase the size of JLabel or decrease the size of image to in JLabel.

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
  • :Thanks for your reply .... I cannot increase jlabel size so i need to resize image . I have gone through following link [link](http://www.mkyong.com/java/how-to-resize-an-image-in-java/) .. is that I need to do ? – Sachin Doiphode Apr 09 '11 at 08:35
  • 1
    @Sachin: Yes you can do like on link. For more help on resizing image in java read [this](http://stackoverflow.com/questions/244164/resize-an-image-in-java-any-open-source-library) – Harry Joy Apr 09 '11 at 08:38
1

One option is to resize the image to fit the JLabel, or increase the size of the JLabel

Shankar Raju
  • 4,356
  • 6
  • 33
  • 52
  • : Thanks for your reply .... I cannot increase jlabel size so i need to resize image . I have gone through following link [link](http://www.mkyong.com/java/how-to-resize-an-image-in-java/) .. is that I need to do ? – Sachin Doiphode Apr 09 '11 at 08:35
  • 1
    @Sachin, yes you can do that. You could also use any tool like Microsoft Picture Manager, picasa, etc to change the size of the image – Shankar Raju Apr 09 '11 at 11:00
0

I have scaled image using [java-image-scaling][1]

[1]: http://code.google.com/p/java-image-scaling/ Library.

With scaling image is very simple just need to add two lines

ResampleOp resampleOp = new ResampleOp (100,200); BufferedImage rescaledTomato = resampleOp.filter(tomato, null);

"tomato " is name of image you want to scale. and (100,200) parameters specifies width & height of scaled image.

Thanks

Sachin Doiphode
  • 431
  • 2
  • 10
  • 24