个性化设置ControlsFX通知

4

我想使用ControlsFX通知类,因为JavaFX似乎没有类似的东西(或者有吗?)。

Notification by ControlsFX

为了使用它,我希望能够自定义通知的颜色和其他样式。有人知道我该如何做吗?
编辑:
通过设置 Notifications.owner(...),通知的样式与我的主应用程序相同,但它会在主应用程序中显示,并不在屏幕右下角。
1个回答

7

Notifications.create().title(...).text(..).action(...).position(Pos.BOTTOM_RIGHT).show();

通过在Java中使用这行代码,并在我的样式表底部添加以下行,我能够自定义通知。

.notification-bar>.pane {
    -fx-background-color: red, yellow, blue;
    -fx-padding: 5 5 5 5;
    -fx-background-insets: 0, 1, 2;
}

.notification-bar>.pane .title {
    -fx-font-size: 1.333em; /*16px;*/
    -fx-text-fill: #000;
    -fx-font-weight: bold;
}

.notification-bar>.pane .label {
    -fx-font-size: 1em; /*12px;*/
    -fx-text-fill: #000;
    -fx-alignment: top-left;
}

/******************************************************************************
 * 
 * Close button
 * 
 *****************************************************************************/

.notification-bar>.pane .close-button {
    -fx-background-color: transparent;
    -fx-background-insets: 0;
    -fx-background-radius: 0;
    -fx-padding: 0 0 0 0;
    -fx-alignment: center;
}

.notification-bar > .pane .close-button:hover {
     -fx-background-color: linear-gradient(#a3a3a3, #8b8b8b 34%, #777777 36%, #777777 63%, #8b8b8b 65%, #adadad);
}

.notification-bar>.pane .close-button:pressed {
     -fx-background-color: linear-gradient(#a3a3a3, #8b8b8b 34%, #777777 36%, #777777 63%, #8b8b8b 65%, #adadad):

}

.notification-bar>.pane .close-button>.graphic {
     -fx-background-color: #fff;
     -fx-scale-shape: false;
     -fx-padding: 4.5 4.5 4.5 4.5; /* Graphic is 9x9 px */
}

.notification-bar>.pane .close-button:hover>.graphic {
     -fx-background-color: #fff;
}

.notification-bar>.pane .close-button:pressed>.graphic {
     -fx-background-color: #fff;
}

.notification-bar>.pane .close-button>.graphic {
     -fx-shape:
    "M395.992,296.758l1.794-1.794l7.292,7.292l-1.795,1.794 L395.992,296.758z M403.256,294.992l1.794,1.794l-7.292,7.292l-1.794-1.795 L403.256,294.992z";
}

1
只是供参考:BOTTOM_RIGHT 是默认值,你不必手动指定它。 :) - alexander
你如何为创建的通知设置样式表? - Hüseyin
请查看 https://dev59.com/T2Uq5IYBdhLWcg3wNtuB#14697419 - st.huber

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接