Results 1 to 4 of 4
- 12-19-2009, 06:59 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 43
- Rep Power
- 0
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| | | ------ | -----------
Java Code:JLabel newLabel = new JLabel(newImage); newLabel.setSize(currentCard.getSize()); newLabel.setPreferredSize(currentCard.getSize());
Thank You for any ideas
-
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.
- 12-19-2009, 08:48 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
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.
- 12-19-2009, 09:21 PM #4
Member
- Join Date
- Nov 2008
- Posts
- 43
- Rep Power
- 0
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()); |
Similar Threads
-
Desktop Icons Applications
By Gajesh Tripathi in forum AWT / SwingReplies: 13Last Post: 07-01-2009, 10:40 AM -
how to compare icons
By panic in forum New To JavaReplies: 9Last Post: 05-21-2009, 09:16 AM -
is there anyone how can help me with image icons please?
By xbox_nutter in forum New To JavaReplies: 4Last Post: 03-27-2009, 11:26 AM -
[SOLVED] Icons path
By janpol1 in forum EclipseReplies: 1Last Post: 03-03-2009, 01:31 PM -
Moving icons on your desktop
By Leprechaun in forum New To JavaReplies: 3Last Post: 12-14-2007, 11:07 AM
Bookmarks