gpt4 book ai didi

javafx - ControlsFX 通知中的粗体文本部分

转载 作者:行者123 更新时间:2023-12-05 03:34:50 25 4
gpt4 key购买 nike

我正在尝试在通知正文中写入粗体文本。

Notifications.create()
.title("My Title")
.text("This is <bold>text</bold>")
.showInformation();

据我所知,只有 .text("my text") 方法可以设置通知的文本。但是我想在那里使用 TextFlow 来修改文本的某些部分。

我也曾尝试为此使用 CSS,但这只能让我更改通知的整体外观,因为明确不支持通过 CSS 设置特定文本。

我现在的问题是:有没有办法对通知中的部分文本设置不同的样式?

最佳答案

现在可以使用了。解决方案是使用.graphic(Node node)。如果您仍想在左侧显示图像,则需要将所有内容都放在 Pane 中并添加一些填充。我从 here 中提取了原始图像.

        BorderPane borderPane = new BorderPane();
borderPane.setLeft(new ImageView(Controller.class.getResource("/dialog-information.png").toExternalForm()));
TextFlow textFlow = new TextFlow();
textFlow.setPadding(new Insets(15, 0, 5, 5));
Text text1 = new Text("This is ");
Text text2 = new Text("bold");
text2.setStyle("-fx-font-weight: bold");
textFlow.getChildren().addAll(text1, text2);
borderPane.setRight(textFlow);
Notifications.create()
.title("My Title")
.graphic(borderPane)
.hideAfter(Duration.seconds(10))
.show();

使用 .show() 而不是 .showInformation/Error/Warning() 很重要,因为那样会覆盖 BorderPane。

结果: example of Notification with TextFlow

关于javafx - ControlsFX 通知中的粗体文本部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70054464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com