Results 1 to 4 of 4
  1. #1
    Krooger is offline Member
    Join Date
    Nov 2008
    Rep Power

    Default Can you change where JLabel paint their icons?

    In my program I have an image that is too large for the JLabel I want to put it in, so it will show only the middle, which is fine since this JLabel is suppose to magnify the image, only I also need to move this image to see different parts of it. Sooo I was thinking an easy way to do this would be to just have the icons top left point start somewhere else so a different part of the image will be in the JLabel.

    Only I cant find a way to do this. Anyone know ifthis can be done?

    For example:
    Java Code:
    | image    |
    |  -----   |
    | |Lable|  |
    |  ------  |
    This is what it does right now when I use the code:
    Java Code:
    JLabel newLabel = new JLabel(newImage);
    So pretty much i give it a large image and then shrink the JLable to a smaller size, but then it shows only the middle. Is there a way to move around where the image is painted so a different part shows up in the label?

    Thank You for any ideas

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    I don't know how to do this easily with ImageIcons, without changing the image, but it can be done with background images on JComponents via one or more of the Graphics#drawImage(...) overloads.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    In this thread on Sun's forum an approach was given describing how to make a label with a rotated icon. The same thing works for icons which are translated. You may also want to follow up the link to camickr's site as it has an example of manipulating text as well as images as part of an icon.

  4. #4
    Krooger is offline Member
    Join Date
    Nov 2008
    Rep Power


    Thanks for the tips, if anyone is intrested this is what I ended up doing...

    I added another JPanel the same size of the JLable and put the JLabel inside of the new JPanel. I then used the following

    Java Code:
    currentLabel.setBounds(xValue, yValue, currentLabel.getIcon().getIconWidth(), currentLabel.getIcon().getIconHeight());
    This simply positioned the JLabel which itself was large elsewhere in the smaller JPanel. Giving the same effect. The only tricky part was getting the right xValue and yValue, since this thing updates in a mouse motion listener as the mouse goes left the picture needs to slide right.

Similar Threads

  1. Desktop Icons Applications
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 13
    Last Post: 07-01-2009, 10:40 AM
  2. how to compare icons
    By panic in forum New To Java
    Replies: 9
    Last Post: 05-21-2009, 09:16 AM
  3. is there anyone how can help me with image icons please?
    By xbox_nutter in forum New To Java
    Replies: 4
    Last Post: 03-27-2009, 11:26 AM
  4. [SOLVED] Icons path
    By janpol1 in forum Eclipse
    Replies: 1
    Last Post: 03-03-2009, 01:31 PM
  5. Moving icons on your desktop
    By Leprechaun in forum New To Java
    Replies: 3
    Last Post: 12-14-2007, 11:07 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