简体   繁体   中英

How to set a window always on top of another specific window in javafx

I have a toolbox that needs to stay always on top of the main window, but not of any other windows. So what I would need is a .setAlwaysOnTop(true) but for a specific window. How do I do that?

When you create the second Stage you have to call initOwner and initModality with Modality.WINDOW_MODAL . Then the new stage is always on top of the other but you can't interact with the parent stage.

For example:

public void createNewStage(Window parent) {
    //... all the other stuff
    Stage onTop = new Stage();
    onTop.initOwner(parent);
    onTop.initModality(Modality.WINDOW_MODAL);
    onTop.show();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM