如何使用 Java (Swing) 获取标题栏的高度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/222940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 11:30:11  来源:igfitidea点击:

How Do You Get the Height of the Titlebar Using Java (Swing)?

javaswinguser-interface

提问by jjnguy

I am getting a MouseEventin Java. the getPoint()method is adding the height of the title bar into the y portion of the coordinate.

MouseEvent在 Java 中获得了一个。该getPoint()方法是将标题栏的高度添加到坐标的 y 部分。

I was wondering how I can find the height of the title bar of the current window in order to offset the y value by the correct amount.

我想知道如何找到当前窗口标题栏的高度,以便将 y 值偏移正确的数量。

采纳答案by Tom Hawtin - tackline

You can find the frame insets by calling the getInsets method (defined in Container). Frame insets are discussed at the top of the Frame API docs. See this question.

您可以通过调用 getInsets 方法(在 Container 中定义)来找到框架插图。Frame 插入在 Frame API 文档的顶部讨论。看到这个问题。

Of course you could always add your mouse listener to the content pane. JFrame has some unexpected behaviour on some methods such as addand setLayout.

当然,您始终可以将鼠标侦听器添加到内容窗格中。JFrame 在某些方法(例如add和 )上有一些意外行为setLayout