title: How to set JFrame or JPanel Background Image in Eclipse Helios
body: <p>I've googled it and found the code:</p>
  
  <pre><code>import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Image;
  
  import javax.swing.ImageIcon;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class ImageTest {
  
    public static void main(String[] args) {
      ImagePanel panel = new ImagePanel(new ImageIcon("background.png").getImage());
  
      JFrame frame = new JFrame();
      frame.getContentPane().add(panel);
      frame.pack();
      frame.setVisible(true);
    }
  }
  
  class ImagePanel extends JPanel {
  
    private Image img;
  
    public ImagePanel(String img) {
      this(new ImageIcon(img).getImage());
    }
  
    public ImagePanel(Image img) {
      this.img = img;
      Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
      setPreferredSize(size);
      setMinimumSize(size);
      setMaximumSize(size);
      setSize(size);
      setLayout(null);
    }
  
    public void paintComponent(Graphics g) {
      g.drawImage(img, 0, 0, null);
    }
  }
  </code></pre>
  
  <p>This worked for me when I create the ImageTest.java file, and put the background.png in the same folder.</p>
  
  <p>But when I paste the same code in Eclipse IDE (in default package) along with the image, then it doesn't set the image as background. Actually it doesn't find the images and this is the reason.</p>
  
  <p>I've tried keeping them both in same <code>package pack;</code> Even then it doesn't find the image, so no output.</p>
  
  <p>I've tried to open the workspace > project folder > war > WEB-INF > classes 
  Then compiled the program from cmd. Still it doesn't show.</p>
  
  <p>I don't know what the problem is. Anyone knowing any solution is most welcomed.</p>
  
  <p>Thanks in Advance.</p>
  
  <p>Setting background directly onto the frame is also welcomed...</p>
  
  <p>I've done all this using code, but when this will be working then I'll be shifting to windows builder for GUI. So will the help from you will work in window builder also?</p>