Search code examples
javauser-interfacejavafxwindow

JavaFX remove titlebar without removing the native borders


I have a JavaFX application and I want to customize the title bar so I can change the design and add a back button.

I tried setting primaryStage.initStyle(StageStyle.UNDECORATED);, but this also removes the native Windows borders, and I can't replicate functionality like window snapping, etc.

I also tried primaryStage.initStyle(StageStyle.UTILITY); but this only changes the title bar to an ugly Java default title bar and I can't remove it (But it keeps the window borders which is great).

Is there some way to remove the title bar without removing the window borders in JavaFX?

I know that this is possible in other App Frameworks like Swing and Electron. Swing is also a Java framework so there has to be some way to do this, right?


Solution

  • The feature you request, "remove titlebar without removing the native borders", is not a feature in the standard JavaFX (21) system. You must implement it yourself or rely on a third-party library.

    Consider the fxstage library which is a JavaFX integration that uses Windows DWM (Desktop Windows Manager), that provides "APIs to create custom window frames for your application". Such a solution is not cross-platform, but there may be some implementations in the FXStage library that allows you to emulate similar functionality on other platforms than Windows.

    I have not used the referenced library and do not know if it will allow the feature you require out of the box or if it would require modifications to perform your required functions.