public void loadBoard()
{
for(int row = 0; row < 5; row++)
for(int col = 0; col < 5; col++)
{
buttons[row][col] = new JButton("");
buttons[row][col].addActionListener(this);
this.add(buttons[row][col]);
}
}
答案 0 :(得分:1)
使用GridLayout
或任何其他Layout
来解决问题。
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(rows, cols));
for (int row = 0; row < rows; ++row)
{
for (int col = 0; col < cols; ++col)
{
panel.add(buttons[row][col]);
}
}
this.add(panel);