Preface
JavaFX显示多窗口其实是非常简单的,需要用两个FXML即可,不用像网上其他人弄的那么麻烦。
环境:
- IDEA
- SceneBuilder V9.0.0
思路
只需要在start()
函数里面事先primaryStage
一样的东西即可。
如下代码:(FXML见后面附)
Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
Stage anotherStage = new Stage()