JPanel com imagem de fundo, com outros painéis sobrepostos
Eu quero ter um JPanel que use uma imagem como plano de fundo. Com isso, quero adicionar novos painéis a esses painéis para que eles fiquem em cima dessa imagem de plano de fundo. Eu tentei o seguinte:
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);
}
A imagem de plano de fundo é exibida, mas o OverlayedPanel1 não é exibido. Alguma ideia?