2

I just started out playing around with CSS in javafx 2. I have some issues with removing CSS style classes from a Pane.

The Pane gets a background color and border based on a boolean value of a custom object:

//kw is a subobject of objects in a listview, everytime the selection is changed 
//the CSS on the pane gets refreshed
resetGUI();
...
if(kw != null){
    if (kw.getAfgewerkt()) {
        pRA.getStyleClass().add("success"); //true
    } else {
        pRA.getStyleClass().add("error"); //false
    }
}
...

The above works.

However before I set the style classes on the pRA Node, I reset the CSS by calling resetGUI() method because when the kw object is null, no CSS should be applied.

public void resetGUI(){
    ...
    pRA.getStyleClass().removeAll("error", "success");
    ...
}

It seems that the removing of the StyleClasses does not work. I want the pRa node to look as 'default' if the kw object is null. Do I have to create a 'default' class myself in the CSS file? That shouldn't be the case I assume?

This is the css:

.error {-fx-background-color: #FBE3E4;-fx-text-fill:#8a1f11;-fx-border-style:solid;-fx-border-color:#FBC2C4;}
.success {-fx-background-color:#E6EFC2;-fx-text-fill:#264409;-fx-border-style:solid;-fx-border-color:#C6D880;}
Perneel
  • 3,317
  • 7
  • 45
  • 66
  • Maybe helpful see [this Q&A](http://stackoverflow.com/q/10887525/682495) – Uluk Biy Jul 18 '12 at 11:08
  • 1
    You are right. Until the previously mentioned bug is fixed, assigning a 'default' class by yourself is a required workaround. – pmoule Jul 18 '12 at 20:35

1 Answers1

0

As commented by pmoule:

Assign the default style yourself by using

pRA.getStyleClass().add("default");

and don't forget to add it in the css

.default {...}
Perneel
  • 3,317
  • 7
  • 45
  • 66