• Post Reply Bookmark Topic Watch Topic
  • New Topic

setting icon size in JLabel

 
Saravanan Subramanyan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I want to set icon size in JLabel. The icon may be big in size say 500*500. But i want to set the image size to 32*32. There is no API in ImageIcon to set the size. I also tried to set using setPreferredSize,setMaximumSize, setMinimumSize,setSize API's in JLabel. But it didn't work for me. Can anyone tell me the procedure for it. It will be very helpful for me.
Thanks and Regards
V.S.Saravanan
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Load your image file into an Image object first. Then call the getScaledInstance() method of Image to scale the image to the size you want. Then make an ImageIcon using the Image object you got back from getScaledInstance().
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you load an image file into an Image object?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways to do it...

is the basic way to load an Image from it's filename in a stand alone application.

Applet's can't use the Toolkit, so they provide the getImage( URL ) method. The new 1.4 JDK also provides the ImageIO classes for reading and writing image data.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!