JavaFX 2.2 Stage always on top

后端 未结 4 1794
Happy的楠姐
Happy的楠姐 2020-12-06 01:19

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

相关标签:
4条回答
  • 2020-12-06 01:35

    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.

    0 讨论(0)
  • 2020-12-06 01:36

    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);
    
    0 讨论(0)
  • 2020-12-06 01:45

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

    0 讨论(0)
  • 2020-12-06 01:56

    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

    0 讨论(0)
提交回复
热议问题