Adam Bien's Weblog

Friday Jan 13, 2012

JavaFX 2.0 CSS Reference

All JavaFX 2 components can be styled with CSS 3. The CSS JavaFX 2 reference is available here: http://docs.oracle.com/javafx/2.0/api/javafx/scene/doc-files/cssref.html. To activate your custom CSS you only have to add a resource containing the CSS styles to the javafx.scene.Scene:


        Scene scene = ...
        scene.getStylesheets().add(this.getClass().getResource("javafxrocks.css").toExternalForm());
        stage.setScene(scene);
        stage.show();



*NEW* Workshop: "Real World Java EE 6/7 Bootstrap" and book: Real World Java EE Night Hacks--Dissecting the Business Tier

Comments:

Careful, this may not work if your net your NetBeans project properties to "Binary Encode JavaFX CSS Files" (in Project Properties->Build->Packaging).
If this is the case you'll have to look for the file "javafxrocks.bss" instead (".css" => ".bss").

You may want to modify your code to check if URL returned when seeking "javafxrocks.css" is null and if it's the case then search for "javafxrocks.bss" instead. This way it should work in both settings.

Posted by Fabrice Bouyé on January 16, 2012 at 12:34 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
Meta
My Recent Book
Java One 2009/2011
...the last 150 posts
...the last 10 comments
Links
License