JavaFX 2.2 Stage always on top

user1706051 picture user1706051 · Oct 10, 2012 · Viewed 23.3k times · Source

I have a normal JFrame (one part of the app) and a second JavaFX window (I can't use a JFrame for the JavaFX stage). The problem is that the JavaFX window should always be on top of all other windows.

I have no idea how I should solve this problem! Any ideas?

Answer

dev009 picture dev009 · May 31, 2014

I know this is a old thread, but things keep on changing. Coming to JDK 8u20 is a new method primaryStage.setAlwaysOnTop(true);

This would be the easiest way to make a stage always on top. For early access to 8u20 visit the website.

public class KeyholeDemo extends Application {
    @Override public void start(Stage primaryStage) {
        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.setAlwaysOnTop(true);

        // code omitted...
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Sample code taken from this nice writeup