Some CSS attributes not working well in JavaFX 2.1

I was not sure if it was me, that was not using the right attributes to style controls via CSS. But today I tested one example from the Ensemble application and noticed it was not working there either.

The one I find most difficult to set right is: -fx-text-fill To change the text color of a label for example:

#pill-left:selected .label {
 /* -fx-text-fill: black; */
 -fx-text-fill:red;
 -fx-effect: dropshadow( one-pass-box , white , 0, 0.0 , 0 , 1 );
}

No matter what I put there, the text always uses the default value color.

I'm using JavaFx 2.1. Maybe this is already fixed in 2.2, but I figure I should point that out, as it is something very basic.

Answers


95% sure this is a bug.

The workarround you need to use -fx-fill: red; instead of -fx-fill-text


Ok, after some extensive testing, I managed to make it work using StyleSheets.

The key is to remove the .label attribute and use just the control's ID, appending the states (:hover, :selected, etc) as needed.

    #pill-left {
    -fx-padding: 5;
    -fx-text-fill:red;
    -fx-border-image-source: url("left-btn.png");
    -fx-border-image-slice: 4 4 4 4 fill;
    -fx-border-image-width: 4 4 4 4;
    -fx-border-image-insets: 0;
    -fx-border-image-repeat: stretch;
    -fx-background-color: null !important; 
}

#pill-left:hover, #pill-left:hover:selected { -fx-text-fill:blue; }
#pill-left:selected { 
    -fx-text-fill:green;
    -fx-border-image-source: url("left-btn-selected.png"); }

As this is all based on code examples taken directly from the ensemble project, that we assume is correct. Many programmers are going to find themselves pulling their hair like I did over this issue.

Anyhow, this is an important lesson learnt on how to use styleSheets with Javafx, avoiding when possible to use anything else than the ID to specify some attributes like the text color.


Need Your Help

how to format date in jquery template in mvc4 web api?

jquery sql asp.net-mvc asp.net-mvc-4

I want to format the date value in my mvc4 web api project.

Java: Saving StreamResult to a file

java xml file stream sax

I am doing some data conversion(like csv) to xml with SAX then using transformer in Java. The result is in StreamResult, and I am trying to save this result to a file.xml but I can't find way to s...