Pynee
Pynee

Reputation: 11

How do I get rid of this gray line at the bottom of the JFrame

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);
};

enter image description here

Upvotes: 0

Views: 71

Answers (1)

Pynee
Pynee

Reputation: 11

Found an answer, looks like it was a 39x39 grid instead of 40x40, once changed the grid just fell into place with no blank spaces.all good

Upvotes: 1

Related Questions