JPanel con imagen de fondo, con otros paneles superpuestos
Quiero tener un JPanel que use una imagen como fondo, con esto quiero agregar nuevos paneles a estos paneles para que se sientan encima de esta imagen de fondo. He probado lo siguiente:
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);
}
Se muestra la imagen de fondo, pero el panel OverlayedPanel1 no se muestra. ¿Algunas ideas?