簡體   English   中英

ControlsFX 通知中的粗體文本部分

[英]Bold Text Parts in ControlsFX Notification

我正在嘗試在通知正文中寫粗體文本。

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

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

我也嘗試為此使用 CSS 但這只能讓我更改通知的整體外觀,因為明確不支持通過 CSS 設置特定文本。

我現在的問題是:有沒有辦法以不同的方式對通知中的文本部分進行樣式設置?

現在可以工作了。 解決方案是使用.graphic(Node node) 如果您仍想在左側顯示圖像,則需要將所有內容放在窗格中並添加一些填充。 我從這里yoinked 原始圖像。

        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。

結果: 使用 TextFlow 的通知示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM