B4J Question [Solved] Get/Read the title bar height

Peter Simpson

Expert
Licensed User
Longtime User
Hello all,
I was just wondering how to get the title bar height. I've searched the web for java fx get title bar height, but can't find what I need.

I just need to know exactly how high/tall the title bar is.

Thank you...
 

Daestrum

Expert
Licensed User
Longtime User
Example for you
B4X:
…
 Dim windowHeight As Double = asJO(MainForm.RootPane).RunMethodJO("getScene",Null).RunMethodjo("getWindow",Null).RunMethod("getHeight",Null)
 Dim sceneHeight As Double = MainForm.RootPane.Height
 Log(windowHeight) ' height including title
 Log(sceneHeight) ' usable height inside rootpane
 Dim titleBarHeight as Double = windowHeight - sceneHeight
 Log($"Window Title bar is  ${titleBarHeight} pixels"$)
End Sub
' uses JavaObject library
Sub asJO(o As JavaObject) As JavaObject
 Return o
End Sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
The WindowHeight probably includes the thin border so the height returned will be a few pixels larger than the title.

Yes on my test the actual title is 23 pixels and the window has 2 borders of 8 pixels.

You can use JNA to get the exact title size, and also the border width. (assuming you are on Windows)
B4X:
#if java
import com.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.*;
public static Integer getTitleHeight(){
 User32 INSTANCE = Native.load("user32", User32.class);
 return INSTANCE.GetSystemMetrics(User32.SM_CYCAPTION);
}
public static Integer getBorderHeight(){
 User32 INSTANCE = Native.load("user32", User32.class);
 return INSTANCE.GetSystemMetrics(User32.SM_CXFRAME);
}
#End If
 
Upvote 0
Top