Ваш код в порядке.Давайте изменим цвет фона BoardColumnPanel
:
public class BoardColumnPanel extends JPanel {
public BoardColumnPanel(int i) {
this.setBackground(new Color(10 * i, 10 * i, 10 * i));
this.setSize(48, 48);
}
}
и инициализируем его другим оттенком серого:
public class BoardPanel extends JPanel {
private GridBagLayout layout;
public BoardPanel() {
initBoardPanel();
}
private void initBoardPanel() {
layout = new GridBagLayout();
this.setLayout(layout);
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
// fill grid
BoardColumnPanel column;
for (int row = 0; row < 10; row++) {
for (int col = 0; col < 10; col++) {
column = new BoardColumnPanel(row + col);
gridBagConstraints.gridx = col;
gridBagConstraints.gridy = row;
gridBagConstraints.ipadx = 5;
gridBagConstraints.ipady = 5;
layout.setConstraints(column, gridBagConstraints);
this.add(column);
}
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.getContentPane().add(new BoardPanel());
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
}
}