Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 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.

like image 525
jjnguy Avatar asked Oct 21 '08 18:10

jjnguy


1 Answers

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.

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.

like image 63
Tom Hawtin - tackline Avatar answered Oct 29 '22 07:10

Tom Hawtin - tackline