說明:按下 [ ~ 開新視窗 ~ ] 按鈕,就會跳出一個新視窗

預覽:

PrtScr capture  

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Test extends Application {

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

    @Override
    public void start(Stage stage) throws Exception {
        StackPane root = new StackPane();

        Scene scene = new Scene(root, 600, 400);
        stage.setScene(scene);
        stage.show();

        Button btn = new Button("~ 開新視窗 ~");

        root.getChildren().add(btn);

        btn.setOnAction((ActionEvent event) -> {
            StackPane root2 = new StackPane();
            Stage stage2 = new Stage();
            stage2.setScene(new Scene(root2, 300, 200));
            stage2.show();
            // 把原先的視窗隱藏起來
            // ((Node) (event.getSource())).getScene().getWindow().hide();
        });
    }
}

arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(1) 人氣()