Application-wide css

David Grieve david.grieve at oracle.com
Thu May 31 06:03:18 PDT 2012


Or add a listener to Scene.sceneProperty.

        stage.sceneProperty().addListener(new ChangeListener<Scene>() {

            public void changed(ObservableValue<? extends Scene> ov, Scene t, Scene t1) {
                t1.getStylesheets().setAll(APPLICATION_WIDE_STYLESHEETS);
            }

        });

Note that popups get their styles from the stylesheets of the scene of the window from which the popup was shown. 

On May 31, 2012, at 4:38 AM, Werner Lehmann wrote:

> Hi David,
> 
> thanks. I can live with that but it was worth a question.
> 
> To explain the background, lets assume I wanted to style all my buttons in all scenes in the same way. And I don't want to duplicate the css obviously. Then it would be handy to have that @import feature because it lives in the css "space". I guess you could say it is personal preference to rather do it in css, not in java. By the way, I am going to have lots of scenes because we are in the process of migrating a largish Swing application, replacing bits and pieces with JFXPanels.
> 
> Maybe I should subclass Scene, Popup, ContextMenu (etc) to add such an application-wide css by default...
> 
> Rgds
> Werner
> 
> On 31.05.2012 03:58, David Grieve wrote:
>> Currently @-keyword statements are ignored and StyleManager isn't going
>> to help you either.
>> 
>> I'm not sure what @import buys you over adding the application wide
>> stylesheet to the stylesheets property of Scene or Parent. I'm not
>> saying it isn't something we shouldn't have. In fact, I could use it
>> myself. But right now, ObservableList<String> getStylesheets() is all we
>> have to work with.
>> 
>> 
>> On May 30, 2012, at 8:32 PM, Richard Bair wrote:
>> 
>>> I've been waiting for David or Jasper to respond :-)
>>> 
>>> Ping!
>>> 
>>> Richard
>>> 
>>> On May 25, 2012, at 8:15 AM, Werner Lehmann wrote:
>>> 
>>>> Hi,
>>>> 
>>>> is there a way to import one css into another? This would allow for
>>>> an application wide stylesheet - to be imported by control or scene
>>>> css. Usually that's the purpose of @import but according to the css
>>>> reference, "@-keyword statements are ignored."
>>>> 
>>>> Alternatively, is it possible to do this in a central place, e.g.
>>>> with the help of StyleManager?
>>>> 
>>>> Rgds
>>>> Werner
>>> 
>> 
>> <http://www.oracle.com>
>> David Grieve | Principal Member of Technical Staff
>> Mobile: +16033121013 <tel:+16033121013>
>> Oracle Java Client UI and Tools
>> Durham, NH 03824
>> <http://www.oracle.com/commitment> Oracle is committed to developing
>> practices and products that help protect the environment


David Grieve | Principal Member of Technical Staff
Mobile: +16033121013 
Oracle Java Client UI and Tools
Durham, NH 03824 
 Oracle is committed to developing practices and products that help protect the environment



More information about the openjfx-dev mailing list