JavaFX: taskbar-less undecorated window

Applications that are launched in Windows OS are by default listed on taskbar. For a utility software like The Console it is not the case. It shouldn’t pollute our task bar or even tray. It should be available under hotkey and that’s it.

Problem is, JavaFX won’t allow us. Previously presented line  stage.initStyle(StageStyle.UNDECORATED)  gives us undecorated window but collides with stage.initStyle(StageStyle.UTILITY) which makes window’s task not visible in taskbar but window itself is then decorated.

Between workarounds I’ve found a solution. TL;DR initialize window using Swing.

Investigating StageStyle.UTILITY

Let’s start with JavaFX internals. So, basically WindowStage class hides this switch case inside:

Setting Window.UTILITY  alone wouldn’t be enough because window border and top bar (title bar without title) would still be visible. By looking deeper at the same switch block we can see this:

Window.POPUP ? Sounds interesting:

To achieve POPUP we could actually use Popup class which extends PopupWindow. Unfortunately, I didn’t make this working properly. When popup once loses focus it can’t regain it.

I’ve found few similiar suggestions over the internet but none workaround did cover my case.

Swing > JavaFX ?

This StackOverflow answer suggests using Swing’s JFrame which provides this:

and of course setAlwaysOnTop(true)  is also possible.

Here goes the solution use Swing instead of JavaFX to create window and initialize it’s style:

And instead of initializing app using javafx.application.Application simply go with this:

Summary

JavaFX is great but it seems I can’t leave Swing. It’s much understendable why JavaFX creators decided to support JavaFX-Swing Interoperability but this case just adds another reason – not really about legacy code but lack of features.

JFrame#setUndecorated() was all I actually needed. This feature should be available out of the box in JavaFX but it’s not. The situation was already covered by bug report JDK-8091566: Taskbar-less Undecorated Transparent Window in 2011.

Some guys say that we should Not mix JavaFX with Swing and I’ll try to keep it that way – besides the window which – unfortunately – covers whole application.