Answer the question
In order to leave comments, you need to log in
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();
}
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);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question