2021-01-12 17:46

Change background color of different snack-bars

Hello, I would like to know how I can change color to different snackbars, for example using classes:

<JFXSnackbar fx:id="snackbarError" styleClass="snackbar-error"/>

.snackbar-error .jfx-snackbar-content{
    -fx-background-color: #f44336;

But does not change color.

I would like to know how I can do to change color of different snack-bars, with classes or with the id.


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39881760 weixin_39881760 4月前

    any update on this issue? i can't change the color by programming

    public static void showSnackBar(String text,  StackPane rootStackPane){
            JFXSnackbar bar = new JFXSnackbar(rootStackPane);
            bar.setStyle("-jfx-background-color: #f44336");
            bar.enqueue(new SnackbarEvent(text));
    点赞 评论 复制链接分享
  • weixin_39653764 weixin_39653764 4月前

    Version: 8.0.3 Try this:

    // Initializing JFXSnackbar
    JFXSnackbar bar = new JFXSnackbar(rootStackPane);
    public void showSnackBar(String message,  String type){
            bar.fireEvent(new JFXSnackbar.SnackbarEvent(message,"info-toast"))
        }else if(type.equals("SUCCESS")){
            bar.fireEvent(new JFXSnackbar.SnackbarEvent(message,"success-toast"))
        }else if(type.equals("WARNING")){
           bar.fireEvent(new JFXSnackbar.SnackbarEvent(message,"warning-toast"))
        }else if(type.equals("ERROR")){
           bar.fireEvent(new JFXSnackbar.SnackbarEvent(message,"error-toast"))
        }else if(type.equals("FATAL")){
           bar.fireEvent(new JFXSnackbar.SnackbarEvent(message,"fatal-toast"))

    Finally your CSS:

        -fx-background-color: BLUE;
        -fx-background-color: GREEN;
        -fx-background-color: YELLOW;
        -fx-background-color: RED;
        -fx-background-color: BLACK;

    You can improve the code according to your needs, regards

    点赞 评论 复制链接分享
  • weixin_39790738 weixin_39790738 4月前

    Why there is not an Enum class ? like this : snackBar.setType(SnackBar.Type.Success);

    点赞 评论 复制链接分享
  • weixin_39942492 weixin_39942492 4月前

    Hello, Thanks for pointing out the issue 👍


    点赞 评论 复制链接分享