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

查看:160
本文介绍了为什么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 pixels长.据我所知,它实际上更像770 (or maybe 769) pixels长.另外,如果您将垂直尺寸设置得非常小(低于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.

框架是带有标题和边框的顶级窗口.边框的大小包括为边框指定的任何区域.可以使用getInsets方法获得边界区域的尺寸.由于边框区域包括在框架的整体大小中,因此边框会有效地遮盖框架的一部分,从而将可用于渲染和/或显示子组件的区域限制为具有(插入)左上角位置的矩形.左侧为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天全站免登陆