Using Image inside a Swing GUI


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Using Image inside a Swing GUI

  1. #1
    Join Date
    Dec 2004
    Posts
    2

    Using Image inside a Swing GUI

    Hi guys,

    What is the 'correct' method for using images inside a Swing GUI?

    Bascially I want to break this down into 2 questions:

    1) How should they be stored, is it preferable to have the image hard-coded into code or as a seperate file?

    2) How can you place them onscreen? At the moment I'm trying to do something as simple as making an "About" box with an image on the left and a bit of jLabel text on the right, however the image seems to get overlayed on top of everything else hence not obeying layout rules and covering up the text even though they are tied to different jPanels.

    Cheers.

  2. #2
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    1) you should be able to store images in a jar (perhaps the same one your class files are in). I would google for information about that.

    2) What about putting your image as the background of a JPanel, setting the panel's size, and placing the panel in the layout? There must be some existing about dialog box code in Sun's tutorials.

  3. #3
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    maybe you could read images in from your jar using java.util.jar.JarInputStream. Unless, of course, there is an even easier method of doing it.

  4. #4
    Join Date
    Dec 2004
    Posts
    2
    How is it possible to set the background of a jPanel to an image? The setBackground method only takes a colour as an argument.

  5. #5
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    can you post your current code that overlays the text/image?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center