Hi guys
i am working on a chessboard. I want to fill the JPanel squares (64) with ImageIcons. When i use the Jpanel setBackgroundColor it works just fine. But when i want to use a JLabel with image i get the wrong result
this is what is looks like and it should fill the whole board with squares.
chessboard.jpg
The following is my code, what am i doing wrong?
package view; import java.awt.*; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.JLabel; import controller.Controller; public class ChessBoardView extends JPanel { private final static ImageIcon DARK_BROWN = new ImageIcon (ChessBoardView.class.getResource("assets/sqb.gif")); private final static ImageIcon LIGHT_BROWN = new ImageIcon (ChessBoardView.class.getResource("assets/sqw.gif"));; private JLabel sqb; private JLabel sqw; public ChessBoardView (Controller controller) { Dimension boardSize = new Dimension(300, 300); setLayout( new GridLayout(8, 8) ); setPreferredSize( boardSize ); setBounds(0, 0, boardSize.width, boardSize.height); sqb = new JLabel (DARK_BROWN); sqw = new JLabel (LIGHT_BROWN); for (int i = 0; i < 64; i++) { JPanel square = new JPanel( new BorderLayout() ); super.add( square ); int row = (i / 8) % 2; if (row == 0) square.add( i % 2 == 0 ? sqw : sqb ); else square.add( i % 2 == 0 ? sqb : sqw ); } } }