我试着做一个17 17网格布局板,但是当我运行代码,我产生被搞砸了,看起来像这样,而不是17 17按键板的板:按钮没有完全加载在网格布局
所以我的问题是为什么董事会显示这样怪异的,我如何得到它显示17 17按钮板,我想要的?
这里是我使用的代码:
public class TheJFrame {
public static final char[][] board = new char[17][17];
public static class TheJFramez {
JFrame boardz = new JFrame("Game of Life");
JPanel panel = new JPanel();
public TheJFramez(){
int r = 0,c;
boardz.setLayout(new GridLayout(board.length,board[r].length,1,1));
for(r=0;r<board.length;r++){
for(c = 0;c<board[r].length;c++){
JButton tats = new JButton(" " + board[r][c] + " ");
panel.add(tats);
}
}
boardz.add(panel);
boardz.setVisible(true);
boardz.setSize(1200, 700);
boardz.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
public static void main(String[] args) {
new TheJFramez();
}
}