Results 1 to 4 of 4
- 12-19-2009, 05: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:
This is what it does right now when I use the code:Java Code:---------- | image | | ----- | | |Lable| | | ------ | -----------
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?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, 07:48 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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, 08: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
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.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, 09:40 AM -
how to compare icons
By panic in forum New To JavaReplies: 9Last Post: 05-21-2009, 08: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, 10:26 AM -
[SOLVED] Icons path
By janpol1 in forum EclipseReplies: 1Last Post: 03-03-2009, 12:31 PM -
Moving icons on your desktop
By Leprechaun in forum New To JavaReplies: 3Last Post: 12-14-2007, 10:07 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks