Results 1 to 10 of 10
  1. #1
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default 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!
    Ah
    Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".

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

    Default Re: Using Image in JLabel? Please Help! :-)

    Quote Originally Posted by Alerhau View Post
    Are there any way in order to do this:

    Changing the JLabels icon with an Image instead of an ImageIcon? :-/

    I'm confused as to what's not working. ImageIcons are easily made from Images, so where are you stuck?

  3. #3
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default 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".

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

    Default Re: Using Image in JLabel? Please Help! :-)

    Quote Originally Posted by Alerhau View Post
    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? :-)
    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.

  5. #5
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default 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);
    The *Image Path*, is just where you have to write the file path.
    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".

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

    Default Re: Using Image in JLabel? Please Help! :-)

    Again, what about the error messages? The compiler often tells you exactly what is wrong.

    /Mr. Perfect

  7. #7
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default 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".

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

    Default Re: Using Image in JLabel? Please Help! :-)

    Quote Originally Posted by Alerhau View Post
    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)
    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));
    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.

  9. #9
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default Re: Using Image in JLabel? Please Help! :-)

    Thankyou! (Mr. Perfect :-D)

    Ah
    Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".

  10. #10
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default 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.
    I do & I will! :-)
    Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".

Similar Threads

  1. How to randomly pick a JLabel that contain image
    By JJay84 in forum AWT / Swing
    Replies: 2
    Last Post: 04-06-2011, 03:15 PM
  2. Replies: 2
    Last Post: 11-24-2010, 02:38 PM
  3. Image On a JLabel
    By corbokhan in forum New To Java
    Replies: 11
    Last Post: 11-06-2010, 12:18 AM
  4. JLabel wont appear in front of background image
    By Andolph23 in forum AWT / Swing
    Replies: 5
    Last Post: 05-27-2010, 01:42 AM
  5. Image in JLabel
    By ishere11 in forum AWT / Swing
    Replies: 2
    Last Post: 04-29-2010, 08:02 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
  •