javaFX 对话框

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

public class DialogTest extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        Button button = new Button("对话框");
        Pane pane = new Pane();
        pane.setPrefWidth(300);
        pane.setPrefHeight(300);
        pane.getChildren().add(button);
        Scene scene = new Scene(pane);

        button.setOnAction(event->{
            Stage stage = new Stage();
            StackPane stackPane = new StackPane();
            stackPane.setPrefWidth(400);
            stackPane.setPrefHeight(400);
            stage.setScene(new Scene(stackPane));

            // 取消最大化 默认:stage.setResizable(true);
            stage.setResizable(false);
            // 取消最小化 默认:stage.initOwner(null);
            stage.initOwner(scene.getWindow());
            stage.show();
        });


        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

 

你可能感兴趣的:(Java,#,JavaFX)