JavaFX 创建的警报对话框太小 [英] JavaFX creates Alert dialog which is too small

查看:41
本文介绍了JavaFX 创建的警报对话框太小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linux 的 Java 11 上使用 JavaFX 11.0.1(openSUSE Tumbleweed 20190314 上的 KDE Plasma 5.12.2)来创建一个 Alert 对话框,它应该如下所示:

但大多数情况下,当创建并显示 Alert 时,它呈现的太小,看起来像这样:

大约五分之一的 Alert 将正确显示.但其余时间显示的是无用的小版本.

用于显示此对话框的代码没有任何异常:

Alert alert = new Alert(Alert.AlertType.ERROR);alert.setTitle("功能缺失");alert.setContentText("功能\"编辑应用程序设置\"尚未完成.");alert.showAndWait();

而且我也尝试过这个建议,添加以下内容来尝试强制大小为有用的东西:

alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);alert.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);

但这给出了完全相同的行为.(请注意,即使为最小宽度和高度设置数值仍然无法解决问题.)

这是 JavaFX 11 中的已知错误吗?是否有一些已知的解决方法可以用来确保 Alert 对话框实际上是可读的?

解决方案

已经存在一个已知问题 报告 完全相同的问题,影响带有 KDE 的 Linux.可以追溯到这个bug,影响了JavaFX 10和11.>

该问题提供了一种有效的解决方法:

alert.setResizable(true);alert.onShownProperty().addListener(e -> {Platform.runLater(() -> alert.setResizable(false));});

但这可能会使警报对话框的大小可以调整.

I'm using JavaFX 11.0.1 on Java 11 in Linux (KDE Plasma 5.12.2 on openSUSE Tumbleweed 20190314) to create an Alert dialog which should look like this:

But most of the time when an Alert is created and shown it is rendered far too small and looks like this:

About one in five times the Alert will display correctly. But the rest of the time the unhelpfully small version is shown instead.

There's nothing unusual about the code being used to display this dialog:

Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Feature absent");
alert.setContentText(
    "Feature \"edit application settings\" has not been finished yet.");
alert.showAndWait();

and I've also tried this advice by adding the following to try to force the size to something useful:

alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);

but this gives exactly the same behaviour. (Note that even setting numeric values for the minimum width and height still don't fix the problem.)

Is this a known bug in JavaFX 11? Is there some known workaround which I can use to make sure the Alert dialogs are actually readable?

解决方案

There is a known issue already reported on the exact same problem, affecting Linux with KDE. It can be traced back to this bug, affecting JavaFX 10 and 11.

The issue provides a workaround that works:

alert.setResizable(true);
alert.onShownProperty().addListener(e -> { 
    Platform.runLater(() -> alert.setResizable(false)); 
});

but that might leave the alert dialog resizable.

这篇关于JavaFX 创建的警报对话框太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆