Reputation: 11
I am trying to create a 40x40 grid using multiple JPanels and after I managed to create it, there is this empty space at the bottom of the JFrame.
public drawBoard() {
createMap(40, 40);
}
public void createMap(int maxX, int maxY) {
String [ ][ ] map = new String [maxX][maxY];
//create 40 panel for the snake to move around in
for (int i=1; i < maxX; i++) {
for (int j=1; j < maxY; j++) {
JPanel panel = new JPanel();
add(panel);
panel.setPreferredSize(pref_size);
String name = String.format("[%d, %d]", i, j);
setLayout(new GridLayout(maxX, maxY, 1, 1)); //change gap to 0 after tests are done
setBackground(Color.GRAY);
panel.setName(name);
}
}
}
private static void createFrame() {
JFrame frame = new JFrame("Snake");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new drawBoard());
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
frame.setResizable(false);
};
Upvotes: 0
Views: 71