2010-01-26 7 views
3

이미지를 배경으로 사용하는 JPanel을 갖고 싶습니다.이 패널에 새 패널을 추가하여이 배경 이미지 위에 놓 이도록하고 싶습니다.다른 패널이 오버레이 된 배경 이미지가있는 JPanel

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); 

    } 

배경 이미지가 표시되지만 OverlayedPanel1 나던 쇼 : 나는 다음과 같은 노력했다. 어떤 아이디어?

+0

페인트()에서 Swing 개체를 만드는 것이 좋지 않습니다! 당신은 Table 생성자 나 클래스의 어떤 메소드에서 그것들을 생성해야한다. – PhiLho

+0

네, 죄송합니다. 예제를 나타 내기 위해 – Aly

+0

패널을 페인팅하지 않습니다. 단지 패널을 그리는 것입니다. 표는 어떤 종류의 개체입니까? Table 객체에 패널을 추가해야하지만 (paint() 메소드에는 포함되지 않음) – Fortega

답변

2

패널에 OverlayedPanel1을 추가하지 않았습니다.

add(OverlayedPanel1); 
관련 문제