title: How to get rid of white 1px line on bottom and right side of a JFrame?
body: <p>I want a <code>JPanel</code> which is currently black but will change color, inside of a <code>JFrame</code>. I only set the size of the panel and then call <code>.pack</code> on my frame, but an ugly white 1px line appears on the bottom and right side of my frame. Why is that and how can I fix it?
  I am currently running Windows 11.</p>
  <pre><code>import javax.swing.JFrame;
  
  public class Main {
      
      private static GamePanel gamePanel;
  
      public static void main(String[] args) {
          
          createWindow();
          
          gamePanel = new GamePanel();
          window.add(gamePanel);
          
          window.pack();
          window.setLocationRelativeTo(null);
          window.setVisible(true);
          
      }
      
      private static JFrame window;
      
      private static void createWindow() {
          window = new JFrame();
          window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          window.setTitle(&quot;My Game&quot;);
          window.setResizable(false);
      }
      
  }
  </code></pre>
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import javax.swing.JPanel;
  
  public class GamePanel extends JPanel {
      
      // Screen settings
      final int originalTileSize = 16;
      final int scaleFactor = 3;
      
      final int tileSize = originalTileSize * scaleFactor;
      final int maxScreenCol = 16;
      final int maxScreenRow = 12;
      final int screenWidth = maxScreenCol * tileSize;
      final int screenHeight = maxScreenRow * tileSize;
      
      // --- Constructor ---
      GamePanel () {
          this.setPreferredSize(new Dimension(screenWidth, screenHeight));
          this.setBackground(Color.black);
          this.setDoubleBuffered(true);
      }
      
      public int getScreenWidth () {
          return screenWidth;
      }
  }
  </code></pre>