JavaFX 2.2 Stage always on top

余生颓废 提交于 2019-11-26 21:13:52

问题


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?


回答1:


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




回答2:


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.




回答3:


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);



回答4:


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



来源:https://stackoverflow.com/questions/12819194/javafx-2-2-stage-always-on-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!