Closed hubersn closed 3 years ago
Well, on Windows 10 and enabled FlatLaf native window decorations (the default), FlatLaf hides the original Windows 10 title bar and paints it itself (using Swing components).
This allows dark window title bars, menu bar embedded into title bar and even adding custom components to title bar:
So it is normal behavior that frame.getInsets().top
is zero (with enabled FlatLaf window decorations).
Try using following, which works with or without FlatLaf:
int titleBarAndMenuBarHeight = SwingUtilities.convertPoint( frame.getContentPane(), 0, 0, frame );
BTW What do you do with the title bar height?
You can of course disable FlatLaf window decorations. Then frame.getInsets().top
returns the title bar height.
FlatLaf.setUseNativeWindowDecorations( false );
According to JavaDoc of (J)Frame.getInsets(), the "top" value should return the height of the title bar: "A Frame object, for example, has a top inset that corresponds to the height of the frame's title bar."
When using FlatLaf 1.5 (FlatLight theme, but I doubt it makes a difference), "top" inset is always 0. Other Look&Feels like Windows or Metal return the true height of the title bar. I am using Windows 10 if that makes a difference (I debugged as far as seeing return values from the native peer, so maybe it does make a difference).