생성자 패널에 int 배열을 보내면 처음으로 gui가 생성되지만 다음 배열에서는 패널/jframe을 업데이트하지 않습니다.jpanel에서 버튼 배열 업데이트
class panel extends JPanel{
public panel(int matriz[][]) {
this.setPreferredSize(new Dimension(300, 300));
this.setLayout(new GridLayout(5, 5));
this.revalidate();
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if(matriz[i][j]==1)
{
JButton boton = new JButton("");
boton.setBackground(Color.yellow);
this.add(boton);
boton.revalidate();
boton.repaint();
}
else
{
JButton boton = new JButton("");
this.add(boton);
boton.revalidate();
boton.repaint();
}
if(j==4) //imprimo pa ver si realmente me esta enviando datos desde creandoVida
System.out.println("n"+matriz[i][j]);
else
System.out.print(matriz[i][j]);
}
}
System.out.println("---");
this.doLayout();
this.revalidate();
this.repaint();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
this.revalidate();
}
thx, 코드를 업데이트했지만 문제가 지속됩니다. "matriz"는 새로운 데이터를 가지고 있지만 jpanel은 전혀 변경이 없습니다 – user3547063
@ user3547063, 편집을 참조하십시오. 적절한 'SSCCE'가 없으면 더 이상 도움을 줄 수 없습니다. – camickr