JavaFX: Alert 弹窗
JavaFX: Alert 弹窗
JavaFX视频教程第22课,DialogPane类和ScheduledService多任务的简单使用
JavaFX视频教程第91课,Alert 弹窗
code.makery:JavaFX Dialogs (official)
DialogPane 类
https://openjfx.cn/javadoc/16/javafx.controls/javafx/scene/control/DialogPane.html
- 标题 Stage 中设置,其他属性设置如top显示、
- DialogPane 继承Pane,需要添加到Scene、Stage中
- DialogPane 头部文字HeaderText、内容ContentText
- DialogPane 添加 button types 按钮和监听
public class DialogController {@FXMLprotected void onHelloButtonClick() {DialogPane dialog = new DialogPane();dialog.setHeaderText(" xhbruce ");dialog.setContentText(" Dialog Sampler ");dialog.getButtonTypes().add(ButtonType.APPLY);dialog.getButtonTypes().add(ButtonType.CANCEL);dialog.getButtonTypes().add(ButtonType.CLOSE);dialog.getButtonTypes().add(ButtonType.FINISH);dialog.getButtonTypes().add(ButtonType.NEXT);dialog.getButtonTypes().add(ButtonType.NO);dialog.getButtonTypes().add(ButtonType.OK);dialog.getButtonTypes().add(ButtonType.PREVIOUS);dialog.getButtonTypes().add(ButtonType.YES);Button close = (Button)dialog.lookupButton(ButtonType.CLOSE);close.setOnAction(event -> {System.out.println(" xhbruce 关闭 ");dialog.setHeaderText(" xhbruce 关闭 ");});Button apply = (Button)dialog.lookupButton(ButtonType.APPLY);apply.setOnAction(event -> {System.out.println(" xhbruce 应用 ");dialog.setHeaderText(" xhbruce 应用 ");});Stage dialogStage = new Stage();Scene dialogScene = new Scene(dialog);dialogStage.setScene(dialogScene);dialogStage.setTitle("退出!");dialogStage.initOwner(DialogApplication.PRIMARY_STAGE);dialogStage.initStyle(StageStyle.UTILITY);dialogStage.initModality(Modality.WINDOW_MODAL);//dialogStage.setAlwaysOnTop(true);dialogStage.setResizable(false);dialogStage.show();}
}
DialogPane 自定义布局
- 图片添加setGraphic
- 扩展内容setExpandableContent
ImageView imageView = new ImageView(PathInfo.getImage("kotlin-Android.PNG"));dialog.setGraphic(imageView);dialog.setExpandableContent(new Text(" 扩展内容 "));
- 添加自定义fxml布局
(界面闪烁)
Node content = PathInfo.loadfxml("expandable.fxml");dialog.setContent(content);
Alert 类
https://openjfx.cn/javadoc/16/javafx.controls/javafx/scene/control/Alert.html
AlertType 类型
public static enum AlertType {/*** The NONE alert type has the effect of not setting any default properties* in the Alert.*/NONE,/*** The INFORMATION alert type configures the Alert dialog to appear in a* way that suggests the content of the dialog is informing the user of* a piece of information. This includes an 'information' image, an* appropriate title and header, and just an OK button for the user to* click on to dismiss the dialog.*/INFORMATION,/*** The WARNING alert type configures the Alert dialog to appear in a* way that suggests the content of the dialog is warning the user about* some fact or action. This includes a 'warning' image, an* appropriate title and header, and just an OK button for the user to* click on to dismiss the dialog.*/WARNING,/*** The CONFIRMATION alert type configures the Alert dialog to appear in a* way that suggests the content of the dialog is seeking confirmation from* the user. This includes a 'confirmation' image, an* appropriate title and header, and both OK and Cancel buttons for the* user to click on to dismiss the dialog.*/CONFIRMATION,/*** The ERROR alert type configures the Alert dialog to appear in a* way that suggests that something has gone wrong. This includes an* 'error' image, an appropriate title and header, and just an OK button* for the user to click on to dismiss the dialog.*/ERROR}
- NONE
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Are you sure you want to format your system?");alert.showAndWait();
- INFORMATION
- WARNING
- CONFIRMATION
- ERROR
Alert 相关属性
- 基础标题、头部文字HeaderText、内容ContentText、一个图标
- Button 添加并监听反馈按钮操作
- 位于stage的top,Alert显示后底部不可操作
public class DialogController {@FXMLprotected void onHelloButtonClick() {Alert alert = createAlert(AlertType.NONE," Xhbruce Alert "," Header Text "," Content Text ",null,DialogApplication.PRIMARY_STAGE,new ImageView(PathInfo.getImage("kotlin-Android.PNG")));alert.getButtonTypes().add(ButtonType.CANCEL);alert.getButtonTypes().add(ButtonType.CLOSE);ButtonType buttonTypeOne = new ButtonType("One");ButtonType buttonTypeCancel = new ButtonType("XhBruce 应用", ButtonBar.ButtonData.APPLY);alert.getButtonTypes().addAll(buttonTypeOne, buttonTypeCancel);//alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel);Optional<ButtonType> result = alert.showAndWait();ButtonType buttonType = result.get();if (buttonType == ButtonType.CANCEL){System.out.println(" ButtonType.CANCEL ");} else if (buttonType == ButtonType.CLOSE) {System.out.println(" ButtonType.CLOSE ");} else if (buttonType == buttonTypeOne) {System.out.println(" ButtonTypeOne ");} else {System.out.println(" ButtonType ");}}// Alert 弹框private Alert createAlert(AlertType alertType, String title, String headerText, String contentText,StageStyle stageStyle, Stage owner, Node graphic) {Alert alert = new Alert(alertType);if (title != null) {alert.setTitle(title);}if (headerText != null) {alert.setHeaderText(headerText);}if (contentText != null) {alert.setContentText(contentText);}if (stageStyle != null) {alert.initStyle(stageStyle);}if (owner != null) {alert.initOwner(owner);alert.heightProperty().addListener(l -> {double centerX = owner.getX() + owner.getWidth() / 2;double centerY = owner.getY() + owner.getHeight() / 2;double alertWidth = alert.getWidth();double alertHeight = alert.getHeight();double alertScreenX = centerX - alert.getWidth() / 2;double alertScreenY = centerY - alert.getHeight() / 2;//System.out.println("alert : alertScreenX=" + alertScreenX + ",alertScreenY=" + alertScreenY);//System.out.println("alert : alertWidth=" + alertWidth + ",alertHeight=" + alertHeight);if (alertScreenX + alertWidth > JavaFXTool.getVisualScreenWidth())alertScreenX = (int) (JavaFXTool.getVisualScreenWidth() - alertWidth);else if (alertScreenX < 0) {alertScreenX = 0;}if (alertScreenY + alertHeight > JavaFXTool.getVisualScreenHeight()) {alertScreenY = (int) (JavaFXTool.getVisualScreenHeight() - alertHeight);} else if (alertScreenY < 0) {alertScreenY = 0;}// Set the X and Y of the Alertalert.setX(alertScreenX);alert.setY(alertScreenY);});}if (graphic != null) {alert.setGraphic(graphic);}//alert.showAndWait();return alert;}
}
JavaFX: Alert 弹窗相关推荐
- swal如何加入html语言,Sweet Alert弹窗点击确定后执行页面跳转等操作
可不可以点击 Sweet Alert 弹窗的确定按钮后跳转页面呢?答案是可以的: 首先参考上文,引入 Sweet Alert 所需的文件,我这里写了一个修改密码的确认框. 点及修改后,会弹出修改成功提 ...
- 原生 js 模拟 alert 弹窗
复制头部的 js 代码到你的 js 文件的任何地方,调用Chef.alert方法传入相应的参数即可并没有什么功能,只是一个提示的作用,可能样式比 alert 的弹窗好看点,css是写在js里的,只要你 ...
- 如何主动触发时间选择器弹窗_请合理使用Alert弹窗
最近做了不少产品的竞品分析,执行一些操作时不免遇到各式各样的模态弹窗,有些弹窗总是意想不到的出现,令我抓狂,导致我不得不认真阅读弹窗内的文字信息,并作出选择:有时候我会习惯性点击右侧的按钮,发现操作后 ...
- Selenium alert 弹窗处理
页面弹窗有 3 种类型: alert(警告信息) confirm(确认信息) prompt(提示输入) 对于页面出现的 alert 弹窗,Selenium 提供如下方法: 序号 方法/属性 描述 1 ...
- js alert弹窗函数
javascript alert弹窗函数 js中的alert函数是指在浏览器中弹出一个提示框. 通常alert用来检验程序运行的状态.可以用来起到调试作用. 具体用法如下 |<html> ...
- VUE3(二十四)自定义alert弹窗组件
我这里自定义了几个alert弹窗组件: 1:带有确定取消的alert弹窗组件:效果如下图所示 代码: /*** 自定义公共函数*/ const utils = {/*** @name: 自定义aler ...
- 软件测试面试题:如何处理一个alert弹窗?
如何处理一个alert弹窗? 处理alert弹窗,需要先跳转到alert上,然后在点击确定或者取消按钮,最后返回到原始的页面,例如:String mainPage = driver.getWindow ...
- RF之处理鼠标悬停和alert弹窗事件
在selenium webdriver中有很多资料提到了处理鼠标悬停事件和对弹窗的处理,robotframework webdriver中很少有这方面的资料,就我遇到的来做一个笔记,也好方法以后的同学 ...
- 自动化测试之alert弹窗的切换
进入页面,定位元素,成功 hello_el=driver.find_element_by_path('//p[@id="hello"]') 点击 hello_el.click() ...
- pythonalert弹窗_python+selenium八:Alert弹窗
# 此弹窗是浏览器自带的弹窗,不是html中的元素 from selenium import webdriver from selenium.webdriver.common.action_chain ...
最新文章
- 解释为什么用梯度下降而不是直接求导数为0的解
- 添加MySql数据库超时设置的相关问题
- SecureRandom
- react项目部署nginx服务器
- 5.3.2 TCP连接管理
- python语言怎么用-python语言中with as的用法使用详解
- 大数据驱动下的微博社会化推荐
- 浅析掌握 Python数据分析与展示的几个要点
- 让IE和Firefox(包括chrome)浏览器默认产生滚动条的滚动槽
- 网页滚动条上下滚动固定元素左右不固定之sticky
- SilverLight小游戏
- 无界面chrome + selenium爬虫
- php 语法验证_在线PHP语法检查器/验证器
- 19年PDYZ冬令营游记
- python基础运用_python基础----python的使用(三)
- 计算机网络工程综合布线目的,浅谈网络工程综合布线系统
- matlab图像画轮毂,轮毂设计及三维造型(全套图纸三维).doc
- [纯理论] FCOS
- java lame_音视频编解码——LAME
- 华为服务器克隆linux,华为RH2288H V3服务器磁盘阵列配置RAID