I am making a chess game, and am using JavaSwing for the GUI. the problem im running into is not having the background of the buttons display correctly. The board consists of 8x8 buttons which i want gray and white. Currently the buttons have an outline of the background color, but the main portion of the button itself is white. How do I make it so the entire button is the same color as the background?
Current Code for making the buttons: (note) the images are added in another method. Button
boardPanel = new JPanel(new GridLayout(8, 8));
boardButtons = new JButton[8][8];
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
boardButtons[i][j] = new JButton();
boardButtons[i][j].setPreferredSize(new Dimension(100, 100));
boardButtons[i][j].setMinimumSize(new Dimension(100, 100));
boardButtons[i][j].addActionListener(buttonListener);
if ((i + j) % 2 == 0) {
boardButtons[i][j].setBackground(Color.WHITE);
} else {
boardButtons[i][j].setBackground(Color.GRAY);
}
boardButtons[i][j].setOpaque(true);
boardPanel.add(boardButtons[i][j]);
}
}
// Create a new panel and add the board panel and white space panel to it
JPanel contentPane = new JPanel();
contentPane.setPreferredSize(new Dimension(1200, 800)); // fixed size for board panel
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
contentPane.add(boardPanel);
JPanel whiteSpacePanel = new JPanel();
whiteSpacePanel.setPreferredSize(new Dimension(400, 800)); // desired size of white space
whiteSpacePanel.setBackground(Color.CYAN);
contentPane.add(whiteSpacePanel);
// Add the new panel to the frame and set some properties
setContentPane(contentPane);
setTitle("Capture The Quad Board");
setResizable(false); // prevent resizing of the window
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
paintBoard();
Current board: