Is there a way to keep the GridLayout one size so it doesnt change when you make a window(frame) bigger or smaller Ill post 2 images so you can see for yourself.
GridBagLayout is this possible? i want to keep 8*8 squares 64 for the chessboard.
chessboard.jpg
chessboard2.jpg
code
package view; import java.awt.*; import javax.swing.BorderFactory; 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(200, 200); setLayout( new GridLayout(8, 8) ); setPreferredSize( boardSize ); setBounds(10, 10, boardSize.width, boardSize.height); setBorder(BorderFactory.createLineBorder(Color.BLACK)); 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 ? new JLabel (LIGHT_BROWN) : new JLabel (DARK_BROWN) ); else square.add( i % 2 == 0 ? new JLabel (DARK_BROWN) : new JLabel (LIGHT_BROWN) ); } } }