Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getStylesheets().add("css_file") has no effect for Scene in JFXPanel

swpalmer-JavaNetJul 28 2011 — edited Jul 28 2011
I'm using Netbeans 7 to build a JavaFx application that has a Swing UI with a JFXPanel. No matter what I try, I can't get the scene to use my stylesheet.
The content of my CSS file is correct. E.g.:

.my-component {
-fx-border-color: black;
-fx-border-width: 2;
-fx-border-radius: 10;
-fx-background-color: #CCFF99;
-fx-background-radius: 10;
}

The path to the CSS file is correct. (e.g. "/packagename/mystyle.css"), I've also tried:
String css = Main.class.getResource("mystyle.css").toExternalForm();
scene.getStylesheets().add(css);

My node (a BorderPane) is set to use the CSS class :

comp2.getStyleClass().add("my-component");

I've verified the syntax by changing it to one of the built-in classes e.g. "button" and the results are seen in the UI.

But I can't get anything from my CSS file to work. There are no error messages logged or exceptions thrown. I can fill the CSS file with nonsense errors and it has no effect.. it's like the file isn't being used at all.

When I use the SAME CSS file in a pure JavaFX application, that is, NOT using JFXPanel, I see a warning if the path to the CSS file is wrong: "WARNING: com.sun.javafx.css.StyleManager$2 run Resource "null" not found."
When the path is correct in that case, it seems to work fine.


What could be the problem?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2011
Added on Jul 28 2011
2 comments
1,310 views