If you want to create a board game, you should use GridLayout , which will help you position your buttons a lot with minimal effort. Something like that:
public JPanel createBoardGame() JPanel boardGame = new JPanel(new GridLayout(numberOfRows,numberOfColumns)); for (int i=0; i<numberOfRows*numberOfColumns; i++) { boardGame.add(new JButton("")); } }
Here is a good article that will help you significantly realize your needs.
Getah source share