Z
Z
zevilcube2019-08-22 20:52:30
Java
zevilcube, 2019-08-22 20:52:30

Window size is set incorrectly in Java swing, what is the problem and what should I do?

There are two classes. One describes the configured JFrame, the other creates an instance of it. I tried to set the window size to 1000x500 using setSize(1000,500). An empty window is created, but has a workspace size of 985x450. Code below.

Main class:

public class Main {
 static Window window;
 public static void main(String[] args) {
   window = new Window();
}


Class with JFrame:

import javax.swing.*;
public class Window extends JFrame {
 public Window() {
   Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize ();
   setLayout(null);
   setSize(1000,500);
   setLocation((screenSize.width-1000)/2, (screenSize.height-800)/2);
   setVisible(true);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
}


What am I doing wrong and how can I fix the problem? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question