Gakkan Krishnarao wrote:

 >Could any body throw light on how to set a JPanel's backgound to any 
 >gif/jpg image. So that the objects like JButtons/JTextAreas always are 
 >above this image.

 >Thanx....

This should give you a good starting position. Put an image file into 
the classpath (I'm loading it trough the classloader). This is a code 
snippet that puts an image in the background of a DesktopPane... Just 
change the root class to JPanel and it should work.

Note that isOpaque is overriden instead of putting setOpaque(false) in 
the constructor. JDesktopPane has "return true" hardcoded in isOpaque (i 
found this after 5 hours of agony), but I think that JPanel can be set 
up correctly without overriding, but you can use this approach just to 
be sure.

Gojko Adzic
http://www.gojko.com

---------------------
   private class ImageDesktopPane extends JDesktopPane
   {
     ImageIcon slika;
     public ImageDesktopPane(String imageFile)
     {
       super();
       setBackground(Color.black);

       slika=new ImageIcon(ClassLoader.getSystemResource(
         imageFile));

     }
     public void paint(java.awt.Graphics g)
     {
       Rectangle r = g.getClipBounds();
       Color c = getBackground();
       if(c == null)
         c = Color.black;
       g.setColor(c);
       g.fillRect(r.x, r.y, r.width, r.height);
       g.drawImage(slika.getImage(),0,0,c,null);
       super.paint(g);
     }
   public boolean isOpaque()
   {
     return false;
   }
}

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to