17

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?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
user1706051
  • 221
  • 1
  • 2
  • 6
  • There is [a feature request in JavaFX-Jira](http://javafx-jira.kenai.com/browse/RT-153) for this, but unfortunately the latest comment on this issue was made in 2011.I wish things were moving faster for such a trivial-looking feature. – a.b Dec 15 '12 at 15:49
  • This guys nailed it on the head. http://stackoverflow.com/questions/15827599/javafx-secondary-screen-always-on-top-of-all-applications – Howard J Jun 30 '15 at 07:55

4 Answers4

36

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

smac89
  • 39,374
  • 15
  • 132
  • 179
dev009
  • 755
  • 8
  • 13
  • This is the way and worked for me. stage.initModality(Modality.APPLICATION_MODAL) also work at some point but the stage will be still behind the task bar. – Lalith J. Oct 25 '14 at 00:07
14

I have a similar problem right now.

I use this line of code to get an always on top effect:

stage.initModality(Modality.APPLICATION_MODAL);

It works fine for me.

Here is the doc.

JackTools.Net
  • 734
  • 6
  • 13
2

Like this (I'm using Alert)

 Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
 stage.setAlwaysOnTop(true);

If you want it on top always blocking other windows, just set:

alert.initModality(Modality.APPLICATION_MODAL);
Kefirchiks
  • 280
  • 4
  • 13
1

AFAIK, there is no API to have JavaFX stage always on top. But you can put JavaFX scene inside JFrame by using JFXPanel.

Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141