views:

96

answers:

1

I want to have a JPanel which uses an image as a background, with this I want to add new panels to this panels so that they sit on top of this background image. I have tried the following:

Image background;
 public Table(){
  super();
   ImageIcon ii = new ImageIcon(this.getClass().getResource("pokerTable.png"));
      background = ii.getImage();
      setSize(Constants.FRAME_WIDTH, Constants.TABLE_HEIGHT);
 }
 @Override
 protected void paintComponent(Graphics g)
 {
  super.paintComponent(g); 
  if (background != null){
        g.drawImage(background, 0,0,this.getWidth(),this.getHeight(),this);
  }

      JButton button = new JButton("hello world");

      JPanel OverlayedPanel1 = new JPanel();
      OverlayedPanel1.setMinimumSize(new Dimension(600,50));
      OverlayedPanel1.setMaximumSize(new Dimension(600,50));
      OverlayedPanel1.setPreferredSize(new Dimension(600,50));
         OverlayedPanel1.add(button, BorderLayout.CENTER);
      OverlayedPanel1.setBackground(Color.yellow);

  }

The background image is displayed but the OverlayedPanel1 doesnt show. Any ideas?

+2  A: 

You didn't add OverlayedPanel1 to the panel.

add(OverlayedPanel1);
Samir Talwar