如何使用Java(Swing)获得标题栏的高度? [英] How Do You Get the Height of the Titlebar Using Java (Swing)?

查看:1202
本文介绍了如何使用Java(Swing)获得标题栏的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

I我想知道如何找到当前窗口标题栏的高度,以便将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.

推荐答案

您可以通过调用getInsets方法(在Container中定义)来查找帧插入。帧插入在Frame API文档的顶部进行了讨论。 查看此问题。

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.

当然,您总是可以将鼠标监听器添加到内容窗格中。 JFrame在某些方法上有一些意想不到的行为,例如 add setLayout

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

这篇关于如何使用Java(Swing)获得标题栏的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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