66import javafx .event .ActionEvent ;
77import javafx .scene .control .Label ;
88import javafx .scene .layout .VBox ;
9+ import javafx .scene .paint .Color ;
10+ import javafx .scene .paint .Paint ;
911import javafx .util .Duration ;
1012
1113/**
@@ -16,7 +18,11 @@ public final class Notification {
1618
1719 public static final Duration DURATION_SHORT = new Duration (2000 );
1820 public static final Duration DURATION_LONG = new Duration (5000 );
21+
1922 private static final Duration TRANSITION_DURATION = new Duration (300 );
23+ private static final Paint PAINT_MESSAGE = Color .WHITE ;
24+ private static final Paint PAINT_ERROR = Color .rgb (255 , 80 , 80 );
25+ private static final Paint PAINT_SUCCESS = Color .LIGHTGREEN ;
2026
2127 private static VBox notificationBox ;
2228 private static Label notificationLabel ;
@@ -41,11 +47,24 @@ public static void show(String text) {
4147 }
4248
4349 public static void show (String text , Duration duration ) {
50+ show (text , duration , PAINT_MESSAGE );
51+ }
52+
53+ public static void error (String text ) {
54+ show (text , DURATION_LONG , PAINT_ERROR );
55+ }
56+
57+ public static void success (String text ) {
58+ show (text , DURATION_LONG , PAINT_SUCCESS );
59+ }
60+
61+ public static void show (String text , Duration duration , Paint textFill ) {
4462 if (hideTimer != null ) {
4563 // show new notification while previous exists
4664 hideTimer .stop ();
4765 transitionOut .stop ();
4866 }
67+ notificationLabel .setTextFill (textFill );
4968 notificationLabel .setText (text );
5069 hideTimer = new Timeline (new KeyFrame (duration .add (TRANSITION_DURATION )));
5170 hideTimer .setOnFinished (Notification ::hide );
0 commit comments