为什么 JFrame setSize() 方法没有正确设置大小? [英] Why does the JFrame setSize() method not set the size correctly?

查看:20
本文介绍了为什么 JFrame setSize() 方法没有正确设置大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用java编程了一个学期左右,遇到过几次这个问题,终于有时间问了.

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.

如果我创建一个 JFrame 然后设置大小,例如 setSize(400,800).该帧实际上不是 800 像素 长.据我所知,它实际上更像 770(或者可能是 769)像素 长.此外,如果您将垂直尺寸设置得非常低(低于 30),则框架甚至不会显示,只有操作系统的顶部窗口栏和框架不会变大,直到您达到超过 30 的值(所以setSize(400,0) 看起来与 setSize(400,20)) 相同.为什么会这样,不难修复,但很奇怪,我很好奇这是为什么?

If I make a JFrame and then set the size, like setSize(400,800) for example. The frame is not actually 800 pixels long. From what I can tell it is actually more like 770 (or maybe 769) pixels long. Also, if you set the vertical size very low (below 30), the frame doesn't even show up, only the top window bar from the OS and the frame doesn't get bigger until you go to a value over 30 (so setSize(400,0) looks the same as setSize(400,20)). Why is this, it's not hard to fix but its weird and I'm curious why this is?

如果您需要有关任何事情的更多信息,请询问,我会告诉您的.

If you need more information about anything just ask and I'll get it to you.

推荐答案

可能是因为边框的大小包括边框的大小.

It's probably because size of a frame includes the size of the border.

Frame 是一个带有标题和边框的顶级窗口.框架的大小包括为边界指定的任何区域.可以使用 getInsets 方法获得边界区域的尺寸.由于边框区域包含在框架的整体大小中,因此边框有效地遮挡了框架的一部分,从而将可用于渲染和/或显示子组件的区域限制在左上角位置为 (insets.left, insets.top),并且具有宽度 - (insets.left + insets.right) 乘以高度 - (insets.top + insets.bottom) 的大小.

A Frame is a top-level window with a title and a border. The size of the frame includes any area designated for the border. The dimensions of the border area may be obtained using the getInsets method. Since the border area is included in the overall size of the frame, the border effectively obscures a portion of the frame, constraining the area available for rendering and/or displaying subcomponents to the rectangle which has an upper-left corner location of (insets.left, insets.top), and has a size of width - (insets.left + insets.right) by height - (insets.top + insets.bottom).

来源:http://download.oracle.com/javase/tutorial/uiswing/components/frame.html

这篇关于为什么 JFrame setSize() 方法没有正确设置大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆