Results 1 to 3 of 3
  1. #1
    shruts is offline Member
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

    Question how to resize image to fit it into a jlabel

    i am using a code in which i want to place my opened image in a label but only a portion of the image is being visible.

    ImageIcon icon= new ImageIcon(tempfilename.getPath());
    l1.setIcon(icon);

    (where l1 is a label and tempfilename contains the file i am opening)

    how can i resize my image in this code ?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: how to resize image to fit it into a jlabel

    One way: create a BufferedImage of the desired size, call createGraphics() to get a Graphics2D object with which to draw on the BufferedImage, and then use one of the Graphics#drawImage(....) overloads that resizes your image for you.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,302
    Rep Power
    20

    Default Re: how to resize image to fit it into a jlabel

    Moved from Advanced Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 2
    Last Post: 11-24-2010, 02:38 PM
  2. How to resize images to fit JLabel?
    By Krooger in forum New To Java
    Replies: 3
    Last Post: 11-24-2010, 01:22 PM
  3. can't resize my JLabel
    By gib65 in forum AWT / Swing
    Replies: 10
    Last Post: 06-25-2010, 05:30 AM
  4. how to resize an image
    By marodia in forum AWT / Swing
    Replies: 2
    Last Post: 08-21-2009, 04:10 AM
  5. Image Resize
    By jithan in forum New To Java
    Replies: 4
    Last Post: 11-07-2008, 09:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •