Why does the JFrame setSize() method not set the size correctly?

后端 未结 6 2093
名媛妹妹
名媛妹妹 2020-12-16 12:40

So I\'ve been programming in java for a semester or so, and I\'ve had this problem a few times and finally got around to asking.

If I make a JFrame and

6条回答
  •  醉酒成梦
    2020-12-16 13:07

    I know that this question is about 6+ years old, but the answer by @Kyle doesn't work.

    Using this

    setSize(width - (getInsets().left + getInsets().right), height - (getInsets().top + getInsets().bottom));
    

    But this always work in any size:

    setSize(width + 14, height + 7);
    

    If you don't want the border to border, and only want the white area, here:

    setSize(width + 16, height + 39);
    

    Also this only works on Windows 10, for MacOS users, use @ben's answer.

提交回复
热议问题