- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
ControlsFX 类 Dialogs
被标记为已弃用。
改用什么?
最佳答案
现在使用 java 8 update 60,即使使用旧的非弃用版本的 controlsfx 也不起作用。因此,解决方案是使用 java 8 update 40 中包含的 javafx 的 native 对话 API(不需要 3rd 方库)。它们不像控件 fx 那样直接且功能丰富。但是为了更快的编码,你可以创建一个包装类,就像我做的这样:
package br.atualy.devolucaodevenda.util;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.StageStyle;
import java.awt.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class FxDialogs {
public static void showInformation(String title, String message) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("Information");
alert.setHeaderText(title);
alert.setContentText(message);
alert.showAndWait();
}
public static void showWarning(String title, String message) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("Warning");
alert.setHeaderText(title);
alert.setContentText(message);
alert.showAndWait();
}
public static void showError(String title, String message) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("Error");
alert.setHeaderText(title);
alert.setContentText(message);
alert.showAndWait();
}
public static void showException(String title, String message, Exception exception) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("Exception");
alert.setHeaderText(title);
alert.setContentText(message);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("Details:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
public static final String YES = "Yes";
public static final String NO = "No";
public static final String OK = "OK";
public static final String CANCEL = "Cancel";
public static String showConfirm(String title, String message, String... options) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("Choose an option");
alert.setHeaderText(title);
alert.setContentText(message);
//To make enter key press the actual focused button, not the first one. Just like pressing "space".
alert.getDialogPane().addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.ENTER)) {
event.consume();
try {
Robot r = new Robot();
r.keyPress(java.awt.event.KeyEvent.VK_SPACE);
r.keyRelease(java.awt.event.KeyEvent.VK_SPACE);
} catch (Exception e) {
e.printStackTrace();
}
}
});
if (options == null || options.length == 0) {
options = new String[]{OK, CANCEL};
}
List<ButtonType> buttons = new ArrayList<>();
for (String option : options) {
buttons.add(new ButtonType(option));
}
alert.getButtonTypes().setAll(buttons);
Optional<ButtonType> result = alert.showAndWait();
if (!result.isPresent()) {
return CANCEL;
} else {
return result.get().getText();
}
}
public static String showTextInput(String title, String message, String defaultValue) {
TextInputDialog dialog = new TextInputDialog(defaultValue);
dialog.initStyle(StageStyle.UTILITY);
dialog.setTitle("Input");
dialog.setHeaderText(title);
dialog.setContentText(message);
Optional<String> result = dialog.showAndWait();
if (result.isPresent()) {
return result.get();
} else {
return null;
}
}
}
使用对话框:
FxDialogs.showInformation("Hi", "Good Morning y'all!");
if (FxDialogs.showConfirm("Choose one baby!", "Can i ask you a question?", FxDialogs.YES, FxDialogs.NO).equals(FxDialogs.YES)) {
FxDialogs.showWarning(null, "Pay attention to my next question!");
String answer = FxDialogs.showTextInput("Are you a pink elephant disguised as a flying pig?", "Tell me!", "No");
FxDialogs.showError(null, "You should not have said " + answer + "!");
FxDialogs.showException("Now i'm angry", "I'm going home...", new RuntimeException("Exception caused by angry dinossaurs"));
}
关于java - 不推荐使用controlsfx 对话框是为了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26341152/
我看过其他类似的问题。我能告诉你的是:该程序在一周前运行。我没有改变场景构建器。我记得下载了一个新的 JRE,它是 1.8.0_101-b13。这是在 Linux 64 位上。在同一个程序中,Lamb
我正在尝试在通知正文中写入粗体文本。 Notifications.create() .title("My Title") .text("This is text") .show
我需要使用密码和密码确认来验证简单的 JavaFX 表单。 validationSupport.registerValidator(passwordInput, V
我想使用 ControlsFX 在 JavaFx 中进行一些验证。我的代码是这样的: ValidationSupport support = new ValidationSupport(); bool
是否可以包含 Controls FX 的组件在 Scene Builder ? 如果是,你能告诉我怎么做吗?如果没有,你能告诉我是否有替代方案吗? 最佳答案 是的,你可以。但不幸的是场景生成器不支持所
我在使用 ControlsFX 进度条对话框时遇到一些问题,有人可以发布一个简单的使用示例吗?我很难弄清楚如何更新进度条以及我应该使用什么类型的 Worker。 我的尝试: Dialogs dialo
我在 javaFX 应用程序中使用对话框来显示正在运行的后台进程。但是,当我在其他计算机上的 Eclipse 中打开相同的源代码时,它会抛出错误。这是我正在使用的对话框的代码 Dialogs.crea
我正在使用ControlFX library在我的项目中使用 PropertySheet 动态生成表单。 Controller 类: public class Controllor imple
我想使用ControlsFX Notifications类,JavaFX 似乎没有提供类似的东西(或者确实有?)。 对于我来说,我希望能够自定义通知的颜色和其他一些样式。有人知道我该怎么做吗? 编辑:
我正在使用 ControlsFX 8.40.9 和最新的 JDK 1.8.0_51 我无法将 RangeSlider 设置为禁用。 设置 slider.setDisable(true); 时,我在日志
在 Swing 中,可以将操作连接到按钮,并且按钮反射(reflect)操作的参数,例如图标、启用性、文本等。 ControlsFX' Action 也可以做到这一点吗? ? 如果是的话怎么办? 最佳
我正在为我正在开发的应用程序学习 API JavaFX,我正在尝试使用 ControlsFX 的 CheckComboBox。 我做了一个测试,以解决在填充 CheckComboBox 的 Obser
我正在使用 ControlsFX 的 BreadcrumbBar,效果很好。我唯一的问题是将其样式设置为如下图所示。使用风景 View 时,我看到该组件只有三个类 .bread-crumb-bar、.
有没有办法在 ControlsFX 向导的最后一页添加 validator ? 我目前在最后一页使用以下内容: public void onEnteringPage(Wizard wizard
我一直在寻找任何使用 ControlsFX PropertySheet 的好例子,但除了这个找不到任何东西。 https://www.google.nl/search?q=Main.java+amaz
我正在使用ControlsFX的SpreadSheetView, 这样我就可以使用 GridBase 实用方法来跨越行/列,如下所示, getGrid().spanColumn(2, row, col
我正在尝试使用 Java 8 设置 ControlsFX CheckComboBox v8.0.3 的默认选定值 我已经尝试过 this question 中接受的答案,但是当我尝试时 CheckCo
是否可以向 CheckComboBox 添加标题/标签?我正在考虑一个不可选择的默认项目。我使用的内联表单没有输入字段的标签。我想为 CheckComboBox 使用内联标题。 最佳答案 据我所知,A
这是我的代码: def list = FXCollections.observableArrayList([]) GridView g = new GridView<>(list);
我正在尝试绑定(bind)一个标签,使其显示在 RangeSlider 的下拇指和上拇指上方。 无论用户将其滑动到何处,标签的位置应始终保持在各自拇指的上方。就像这样: 我的方法是将监听器附加到每个拇
我是一名优秀的程序员,十分优秀!