title: 2D grid is not fitting in JFrame for pathing visualizer
body: <p>I am trying to create a 2D grid with node sizes depending on the size of the height/width of the frame but whenever I run the program, the bottom row and right columns are somewhat cut off. Here is my execution code:</p>
  <pre><code>public class PathfindingVisualizer {
      public static void main(String[] args) {
          Grid grid = new Grid(10,10, new Dimension(1000, 1000));
  
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  new GridFrame(grid);
              }
          });
      }
  }
  </code></pre>
  <p>Here is the Grid class:</p>
  <pre><code>package gui;
  
  import javax.swing.*;
  import java.awt.*;
  import java.util.Arrays;
  
  public class Grid extends JPanel {
      private final int rows, cols;
      private final Node[][] grid;
      private Node start, end;
      private final Dimension size;
      private int nodeSize;
  
      public Grid(int rows, int cols, Dimension size) {
          this.rows = rows;
          this.cols = cols;
          this.grid = new Node[cols][rows];
          this.size = size;
          this.nodeSize = getWidth() / cols;
          initializeGrid();
      }
  
      public void initializeGrid() {
          // populate grid as a 2D array of Nodes
          for (int col=0; col&lt;cols; col++) {
              for (int row=0; row&lt;rows; row++) {
                  grid[col][row] = new Node(col, row);
              }
          }
  
          // create neighbors for all the Nodes
          for (int col=0; col&lt;cols; col++) {
              for (int row=0; row&lt;rows; row++) {
                  setNeighbors(col, row);
              }
          }
  
          // create start and end points for pathfinding
          start = grid[0][0];
          end = grid[cols-1][rows-1];
      }
  
      private void setNeighbors(int col, int row) {
          int[][] directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  
          for (int[] direction : directions) {
              int neighborCol = direction[0] + col;
              int neighborRow = direction[1] + row;
  
              if (neighborCol &gt;= 0 &amp;&amp; neighborCol &lt; cols &amp;&amp;
                  neighborRow &gt;= 0 &amp;&amp; neighborRow &lt; rows) {
                  if (Arrays.equals(direction, new int[]{1, 0})) {
                      grid[col][row].setDown(grid[neighborCol][neighborRow]);
                  }
                  if (Arrays.equals(direction, new int[]{-1, 0})) {
                      grid[col][row].setUp(grid[neighborCol][neighborRow]);
                  }
                  if (Arrays.equals(direction, new int[]{0, 1})) {
                      grid[col][row].setRight(grid[neighborCol][neighborRow]);
                  }
                  if (Arrays.equals(direction, new int[]{0, -1})) {
                      grid[col][row].setLeft(grid[neighborCol][neighborRow]);
                  }
              }
          }
      }
  
      @Override
      protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.setColor(Color.BLACK);
          for (int col=0; col&lt;cols; col++) {
              for (int row=0; row&lt;rows; row++) {
                  g.drawRect(col*nodeSize, row*nodeSize, nodeSize, nodeSize);
              }
          }
      }
  
      public int getRows() {
          return rows;
      }
  
      public int getCols() {
          return cols;
      }
  
      public Node[][] getGrid() {
          return grid;
      }
  
      @Override
      public Dimension getSize() {
          return size;
      }
  
      public int getHeight(){
          return (int) size.getHeight();
      }
  
      public int getWidth(){
          return (int) size.getWidth();
      }
  }
  </code></pre>
  <p>And here is the GridFrame class:</p>
  <pre><code>package gui;
  
  import javax.swing.*;
  import java.awt.*;
  
  public class GridFrame {
      public GridFrame(Grid grid) {
          JFrame frame = new JFrame(&quot;Pathfinding Visualizer&quot;);
          frame.setPreferredSize(grid.getSize());
          frame.setContentPane(grid);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
      }
  }
  </code></pre>
  <p>I have also been messing around with implementations that have a draw function w/in the Node class but haven't had any luck with that as of yet.</p>
  <p>The goal here is to make a pathing visualizer. This is my first Java project, so any help is helpful!</p>
  <p>EDIT:
  Here is the Node class as well:</p>
  <pre><code>package gui;
  
  public class Node {
      private final int row, col;
      private Node up, down, left, right;
      private boolean start, end, wall, visited;
  
      public Node(int col, int row) {
          this.col = col;
          this.row = row;
      }
  
      public int getRow() {
          return row;
      }
  
      public int getCol() {
          return col;
      }
  
      public Node getUp() {
          return up;
      }
  
      public void setUp(Node up) {
          this.up = up;
      }
  
      public Node getDown() {
          return down;
      }
  
      public void setDown(Node down) {
          this.down = down;
      }
  
      public Node getLeft() {
          return left;
      }
  
      public void setLeft(Node left) {
          this.left = left;
      }
  
      public Node getRight() {
          return right;
      }
  
      public void setRight(Node right) {
          this.right = right;
      }
  
      public boolean isStart() {
          return start;
      }
  
      public void setStart(boolean start) {
          this.start = start;
      }
  
      public boolean isEnd() {
          return end;
      }
  
      public void setEnd(boolean end) {
          this.end = end;
      }
  
      public boolean isWall() {
          return wall;
      }
  
      public void setWall(boolean wall) {
          this.wall = wall;
      }
  
      public boolean isVisited() {
          return visited;
      }
  
      public void setVisited(boolean visited) {
          this.visited = visited;
      }
  }
  </code></pre>