• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

setting icon size in JLabel

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you load an image file into an Image object?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic