0

I'm displaying a window as seen in this picture below, which is set to 640 x 640.

Window

As you can see, the squares, which are 32 x 32, do not line up correctly. (20 squares by 20 squares)

I took a crude screenshot and discovered that the dimensions had been reduced by tens of pixels. What's going on here?

Here is my code

package main;

import javax.swing.JFrame;

public class Game extends JFrame {
    
    private GameScreen gameScreen;
    
    public Game() {
        
        setSize(640, 640);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        gameScreen = new GameScreen();
        add(gameScreen);
        
    }

    public static void main(String[] args) {
        
        Game game = new Game();
        
    }

}
GraysonA
  • 9
  • 2
  • 2
    the size set in code is the total sizeof the frame (its *outside*), not just of the `gameScreen` – user16320675 Nov 14 '21 at 20:16
  • 1
    (WIndows 10 or later:despite not showing the window border, there is one there!) also recommended to call `setVisible` after adding all components and I do not like to extend `JFrame` (unless changing/extending its functionality, not the case here) – user16320675 Nov 14 '21 at 20:26

0 Answers0