import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
/**
* dialogPane类
*/
public class Demo21 extends Application {
private static final String url = "icon/icon.png";
@Override
public void start(Stage primaryStage) throws Exception {
Button button = new Button("打开弹窗");
button.setOnAction((event) -> {
DialogPane dialogPane = new DialogPane();
dialogPane.setHeaderText("warning");
dialogPane.setContentText("warning!!!!!");
dialogPane.getButtonTypes().add(ButtonType.CANCEL);
dialogPane.getButtonTypes().add(ButtonType.APPLY);
Button cancelButton = (Button) dialogPane.lookupButton(ButtonType.CANCEL);
cancelButton.setOnAction(clickEvent -> {
});
Button applyButton = (Button) dialogPane.lookupButton(ButtonType.APPLY);
applyButton.setOnAction(clickEvent -> {
});
ImageView imageView = new ImageView(url);
dialogPane.setGraphic(imageView);
dialogPane.setExpandableContent(new Text("扩展内容"));
Scene scene = new Scene(dialogPane);
Stage stage = new Stage();
stage.setScene(scene);
stage.initStyle(StageStyle.UTILITY);
stage.initModality(Modality.WINDOW_MODAL);
stage.initOwner(primaryStage);
stage.setResizable(false);
stage.setTitle("tips");
stage.show();
});
AnchorPane anchorPane = new AnchorPane();
anchorPane.setStyle("-fx-background-color: #ffffff");
anchorPane.getChildren().add(button);
AnchorPane.setTopAnchor(button, 100.0);
AnchorPane.setLeftAnchor(button, 100.0);
Scene scene = new Scene(anchorPane);
primaryStage.setScene(scene);
primaryStage.setTitle("javafx");
primaryStage.setWidth(800);
primaryStage.setHeight(800);
primaryStage.show();
}
}
19.JavaFx DialogPane类
最新推荐文章于 2024-08-04 11:01:37 发布