How to style FXML-defined popups?

Werner Lehmann lehmann at media-interactive.de
Thu May 31 02:03:48 PDT 2012


Hi,

the following works as an FXML alternative to adding the stylesheet in 
Java code:

>   <stylesheets>
>     <String fx:value="/the/fully/qualified/path/to/the/desired.css"/>
>   </stylesheets>

It also requires this

> <?import java.lang.String?>

which was a bit unexpected. URL did not work here because it was not 
coerced to a string.

However, this does not help with FXML-defined popups and contextmenus 
because those do not have a stylesheet property. According to my tests 
I'd have to set the property contextmenu.scene.root.stylesheets - not 
sure how to do that in FXML and it is a bit long-winded anyway.

Rgds
Werner

On 31.05.2012 03:51, FXML Guide wrote:
> Hi;
>
> Have tried importing your stylesheet directly into your FXML file?
>
> <stylesheets>
> <URL value="@thestylesheetname.css" />
> </stylesheets>
>
> TA
>> Hi,
>>
>> I am using FXML to prepare popups and contextmenus in an fx:define block:
>>
>>> <fx:define>
>>> <Popup fx:id="popup" styleClass="my-popup" .../>
>>> <ContextMenu fx:id="contextmenu" styleClass="my-contextmenu" .../>
>>> </fx:define>
>>
>> Unfortunately those popups do not inherit the stylesheets of the scene
>> which the fxml is loaded into. Instead, I have to do this after
>> loading for each popup and contextmenu:
>>
>>> contextmenu.getScene().getRoot().getStylesheets().addAll(...);
>>
>> Is there a simpler way, maybe something I can do directly in FXML... a
>> clever binding or somesuch?
>>
>> Rgds
>> Werner


More information about the openjfx-dev mailing list