简体   繁体   中英

JAVAFX: Any way to get a stage that is already open?

First, I'm sorry about my english and i am new here.. I'd like to know.. is there a way to get the stages that are already open on javafx ?

** Something like "Application.OpenForms" from C#

For example:

I have a menu with 3 items: Register, Reports and Help. When I click on Register, it will open the register form for me. Then I click on Reports, it will open the reports for me. If I click on register again, the form that is already open will request the focus instead open a new form.

Someone help me, please ?

You can define your main stage as a static variable. For example, you have the following main file.

public class Main extends Application {
public static Stage main_stage;
@Override
public void start(Stage stage) throws Exception{
    main_stage = stage;
    stage.show();
}
public static void main(String[] args) {
    launch(args);
}

So you can access your main_stage from anywhere by using Main.main_stage.

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