当屏幕分辨率改变时,组件之间的间隔不会改变。为什么?
我使用 Gridbaglayout 在 Swing 中创建了一个包含 10 个组件(5 个标签和 5 个文本字段)的表单。
当我的屏幕分辨率改变时,组件之间的间距不会改变。为什么?
I have created a form in Swing with 10 components (5 labels and 5 textfields), using Gridbaglayout.
When my screen resolution changes, the separation between the components is not changing. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GridBagLayout 使用像素作为度量单位。您可以使用 java.awt。 Toolkit.getScreenResolution() 获取像素密度,然后相应地缩放间距。您还可能会发现 java.awt .GraphicsConfiguration.getNormalizingTransform() 有用;它允许您在 72 个单位等于 1 个物理英寸的坐标系中工作。
GridBagLayout uses pixels as the unit of measure. You can use java.awt.Toolkit.getScreenResolution() to get the pixel density and then scale your spacing accordingly. You also might find java.awt.GraphicsConfiguration.getNormalizingTransform() useful; it allows you to work in a coordinate system where 72 units is 1 physical inch.