点击登录,提示一个对话框
//这里,Jfoenix开发团队没有考虑到对话框的创建是要点击之后生成的,demo直接是在Main.java文件里面写的 //我是在issue那里找到了一位外国开发者,直接在controller里面创建对话框显示 //我稍微折腾一下,准备弄个想Android那样,对话框可以由一行代码生成,这里就暂时使用外国开发者代码凑合凑合 //使用的话,如果Stage的宽度不长,对话框显示会不完全,得在Main.java中设置一下 final JFXAlert<String> alert = new JFXAlert<>((Stage) tfPassword.getScene().getWindow()); alert.initModality(Modality.APPLICATION_MODAL); alert.setOverlayClose(false); // Create the content of the JFXAlert with JFXDialogLayout JFXDialogLayout layout = new JFXDialogLayout(); layout.setHeading(new Label("Enter Username")); layout.setBody(new VBox(new Label("Please enter the username of the person you would like to add."))); // Buttons get added into the actions section of the layout. JFXButton addButton = new JFXButton("ADD"); addButton.setButtonType(JFXButton.ButtonType.FLAT); addButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent addEvent) { // When the button is clicked, we set the result accordingly alert.setResult("hello"); alert.hideWithAnimation(); } }); JFXButton cancelButton = new JFXButton("CANCEL"); cancelButton.setCancelButton(true); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent closeEvent) { alert.hideWithAnimation(); } }); layout.setActions(addButton, cancelButton); alert.setContent(layout); alert.showAndWait(); 测试Java开发桌面程序学习(二)————fxml布局与控件学习 (2)
内容版权声明:除非注明,否则皆为本站原创文章。