Results 1 to 12 of 12
  1. #1
    Yannick is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default ImageIcon background

    Hi, i have created a simple program and i wanted to put an ImageIcon on the background but when i put it, the buttons and the labels stay behind of the image so its like i just can see the image...any idea?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default

    Yup. Go through this:
    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI with JFC/Swing)

    db

    edit To get better help sooner, post a Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that clearly demonstrates your problem. Link:
    SSCCE : Java Glossary

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    13

    Default

    Try changing the order you add components to the pane. If you added the ImageIcon last, add it first, or the other way around.

  4. #4
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I think Steve11235 someplace right. But you should use not IconImage but Image instead )
    FlowLayout()

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    13

    Default

    Webuser is right about not trusting me too much on this. I haven't done such a thing, and I never layer my components.

    I found a site that provides sample code for doing this. It looks pretty simple, actually.

  6. #6
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I have some skills with this ) I used to have many components right on the Image background so I can tell you not to use ImageIcon but Image instead ) ImageIcon is actually for JButtons and so on... not for JPanels )

  7. #7
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    13

    Default

    You're right. The Graphics.draw() method requires an Image, not an ImageIcon.

    However, since I haven't dealt that much with Image, the only way I know to get an Image is to instantiate an ImageIcon, which is easy, and then to use ImageIcon.getImage(). That's the approach used in the sample code I linked to.

    Is there a more direct way to obtain an image from a URL?

  8. #8
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Is there a more direct way to obtain an image from a URL?
    Yeah there is )))
    you can use code like a:
    Image image=ImageIO.read(anchor.class.getResourceAsStrea m( "pic.PNG" ))
    It is quite useful. Try it )

  9. #9
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    13

    Default

    Cool. This more direct.

    I also saw the javax.imageio.ImageIO utility class, which has read() methods taking a File or a URL parameter. They return a BufferedImage.

    Thanks for the tip.

  10. #10
    Ciwan is offline Banned
    Join Date
    Dec 2008
    Location
    Earth
    Posts
    87
    Rep Power
    0

    Default

    Wow cool, thanks for the tip about getting images guys :)

  11. #11
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I am glad that hepled )

  12. #12
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    13

    Default

    WebUser- Thanks from me, too. Now, I see that *you* pointed to ImageIO. Duh. I only saw Image...

Similar Threads

  1. How to Run a .exe in background???
    By jazz2k8 in forum New To Java
    Replies: 9
    Last Post: 01-21-2011, 11:27 AM
  2. send imageIcon over RMI
    By nadia in forum Advanced Java
    Replies: 4
    Last Post: 01-06-2009, 03:41 PM
  3. ImageIcon and size
    By wokena in forum Java 2D
    Replies: 3
    Last Post: 12-21-2008, 08:47 AM
  4. Detect loading of ImageIcon from URL?
    By barkster in forum Java Applets
    Replies: 1
    Last Post: 01-29-2008, 07:04 PM
  5. copy image/imageicon into a file on disk
    By archanajathan in forum Advanced Java
    Replies: 2
    Last Post: 11-22-2007, 06:21 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
  •