Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaFX中让场景和舞台同时交互_Java_User Interface_Javafx - Fatal编程技术网

在JavaFX中让场景和舞台同时交互

在JavaFX中让场景和舞台同时交互,java,user-interface,javafx,Java,User Interface,Javafx,大家好,我正在尝试创建一个应用程序,但是如果我在舞台顶部打开一个场景,我无法与两个窗口交互,只能与顶部的窗口交互。经过研究,我猜这是不可能做到的,我将不得不修改代码,将大型MainApp划分为更小的类,并使用Platform.runLater和一个主类中的线程在单独的线程上加载每个场景和阶段。我试过了,但没有成功 public class MainApp extends Application { private Stage primaryStage; private BorderPane r

大家好,我正在尝试创建一个应用程序,但是如果我在舞台顶部打开一个场景,我无法与两个窗口交互,只能与顶部的窗口交互。经过研究,我猜这是不可能做到的,我将不得不修改代码,将大型MainApp划分为更小的类,并使用Platform.runLater和一个主类中的线程在单独的线程上加载每个场景和阶段。我试过了,但没有成功

public class MainApp extends Application {

private Stage primaryStage;
private BorderPane rootLayout;


@Override
public void start(Stage primaryStage) {
    this.primaryStage = primaryStage;
    this.primaryStage.setTitle("AddressApp");

    // Set the application icon.
    this.primaryStage.getIcons().add(new Image("file:resources/images/address_book_32.png"));

    initRootLayout();

    showPersonOverview();
}

/**
 * Initializes the root layout and tries to load the last opened
 * person file.
 */
public void initRootLayout() {
    try {
        // Load root layout from fxml file.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class
                .getResource("view/RootLayout.fxml"));
        rootLayout = (BorderPane) loader.load();

        // Show the scene containing the root layout.
        Scene scene = new Scene(rootLayout);
        primaryStage.setScene(scene);

        // Give the controller access to the main app.
        RootLayoutController controller = loader.getController();
        controller.setMainApp(this);

        primaryStage.show();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Try to load last opened person file.
    File file = getPersonFilePath();
    if (file != null) {
        loadPersonDataFromFile(file);
    }
}

/**
 * Opens a dialog to show birthday statistics.
 */
public void showBirthdayStatistics() {
    try {
        // Load the fxml file and create a new stage for the popup.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource("view/BirthdayStatistics.fxml"));
        AnchorPane page = (AnchorPane) loader.load();
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Birthday Statistics");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.initOwner(primaryStage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);

        // Set the dialog icon.
        dialogStage.getIcons().add(new Image("file:resources/images/calendar.png"));

        // Set the persons into the controller.
        BirthdayStatisticsController controller = loader.getController();
        controller.setPersonData(personData);

        dialogStage.show();

    } catch (IOException e) {
        e.printStackTrace();
    }
}



/**
 * Returns the main stage.
 * @return
 */
public Stage getPrimaryStage() {
    return primaryStage;
}

public static void main(String[] args) {
    launch(args);
}
}

在上图中,我只能与生日静力学场景交互,而不能与初级阶段交互

线路:

dialogStage.initModality(Modality.WINDOW_MODAL);
使新窗口成为阻止其他窗口的任何事件的模式

您应将其替换为:

dialogStage.initModality(Modality.NONE);
你可以读更多