Results 1 to 10 of 10
- 09-07-2011, 05:39 PM #1
Using Image in JLabel? Please Help! :-)
Are there any way in order to do this:
Changing the JLabels icon with an Image instead of an ImageIcon? :-/
I really need to get it working.
Thanks!
AhCurrently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
-
Re: Using Image in JLabel? Please Help! :-)
- 09-07-2011, 05:57 PM #3
Re: Using Image in JLabel? Please Help! :-)
Well, first of all. I am actually making the Image to an ImageIcon. But for some reason it says that something is wrong. :-/
Also getting compile errors? ... Any ideas? :-)Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
-
Re: Using Image in JLabel? Please Help! :-)
Seriously.
How can we even begin to guess what is wrong based on this information? Don't you think you need to show some code, some error messages if any are shown? I know we're smart and good looking, but we can't read minds.
Please read the link in my signature on "how to ask smart questions" because sorry to say but your last one isn't.
- 09-07-2011, 06:14 PM #5
Re: Using Image in JLabel? Please Help! :-)
Okay, Mr. Perfect...
I will give you all of the information that I think you might need.
First of all I can show you the part of the code that I have no idea of what's wrong in.
Java Code:Image img = new ImageIcon("*Image Path*").getImage(); img = createImage(new FilteredImageSource(img.getSource(), new CropImageFilter(0, 0, 20, 20))); JPanel Panel = new JPanel(); JLabel Label = new JLabel(); Label.setIcon(img); Panel.add(Label); add(Panel, BorderLayout.CENTER);
All this is into the Constructor of the class that extends my JFrame.Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
-
Re: Using Image in JLabel? Please Help! :-)
Again, what about the error messages? The compiler often tells you exactly what is wrong.
/Mr. Perfect
- 09-07-2011, 06:29 PM #7
Re: Using Image in JLabel? Please Help! :-)
Then I just get this:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method setIcon(Icon) in the type JLabel is not applicable for the arguments (Image)
at ab.<init>(ab.java:16)
at aa.main(aa.java:7)
Is there any way to change an Image into an Icon? (Normal Icon)Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
-
Re: Using Image in JLabel? Please Help! :-)
Yes, just use the ImageIcon constructor.
So this is changed from:
Java Code:JLabel Label = new JLabel(); Label.setIcon(img);
to this:
Java Code:JLabel Label = new JLabel(); Label.setIcon(new ImageIcon(img));
- 09-07-2011, 07:47 PM #9
Re: Using Image in JLabel? Please Help! :-)
Thankyou! (Mr. Perfect :-D)
AhCurrently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-07-2011, 07:48 PM #10
Re: Using Image in JLabel? Please Help! :-)
Do you now see how it was impossible to even guess how to help you without the code and error message? Again, please read the link on smart questions, as it does provide useful tips, tips that have helped me with many of my questions.Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
Similar Threads
-
How to randomly pick a JLabel that contain image
By JJay84 in forum AWT / SwingReplies: 2Last Post: 04-06-2011, 04:15 PM -
Help: How to auto-resize the image icon to fit in the jlabel
By weikang in forum AWT / SwingReplies: 2Last Post: 11-24-2010, 03:38 PM -
Image On a JLabel
By corbokhan in forum New To JavaReplies: 11Last Post: 11-06-2010, 01:18 AM -
JLabel wont appear in front of background image
By Andolph23 in forum AWT / SwingReplies: 5Last Post: 05-27-2010, 02:42 AM -
Image in JLabel
By ishere11 in forum AWT / SwingReplies: 2Last Post: 04-29-2010, 09:02 AM
Bookmarks