<div style="font-family: 'verdana'; font-size: 12px; color: #000;"><span style="background-color: #ffffff;">This is indeed weird and I agree that this makes testability worse, <br>while also leaving out that you might not use a Control but still need the default user agent stylesheet.</span></div>
<div style="font-family: 'verdana'; font-size: 12px; color: #000;"><span style="background-color: #ffffff;"> </span></div>
<div style="font-family: 'verdana'; font-size: 12px; color: #000;"><span style="background-color: #ffffff;">I think it probably makes the most sense inside Application / after Bootstrapping the PlatformImpl class?</span></div>
<div style="font-family: 'verdana'; font-size: 12px; color: #000;"><span style="background-color: #ffffff;"> </span></div>
<div style="font-family: 'verdana'; font-size: 12px; color: #000;"><span style="background-color: #ffffff;">-- Marius</span></div>
<div id="sub-body-container" style="margin: 10px 5px 5px 10px; padding: 10px 0px 10px 10px; border-left: 2px solid rgb(195, 217, 229);">
<div style="margin: 0px 0px 10px;">
<div><strong>Gesendet: </strong>Freitag, 28. November 2025 um 21:02</div>
<div><strong>Von: </strong>"John Hendrikx" <john.hendrikx@gmail.com></div>
<div><strong>An: </strong>OpenJFX <openjfx-dev@openjdk.org></div>
<div><strong>Betreff: </strong>JavaFX testability of Control</div>
</div>
<p>I'm seeing something odd in Control.  It tries to initialize the default platform user agent stylesheet in a static initializer.  This makes any subclass of Control hard to test (as a unit) as it will try to initialize the entire JavaFX platform. </p>
<p>I see little need for this.  The stylesheet is loaded actually in 3 different places:</p>
<p>- Control<br>- PopupControl<br>- Application (if calling <span style="background-color: #ffffff; padding: 0.0px 0.0px 0.0px 2.0px;"><span style="color: #000000; background-color: #ffffff; font-family: Consolas; font-size: 11.0pt; white-space: pre;"><span style="color: #000000; background-color: #d4d4d4;">setUserAgentStylesheet</span></span></span> with null)</p>
<p>Could we perhaps just defer this loading? Or perhaps load it when another class is created that is required for CSS processing?</p>
<p>I could imagine the following options:</p>
<p>- Initialize this when Window or Scene class is loaded (required to make use of CSS)<br>- Initialize this somewhere in Application as a default<br>- Instead of initializing the whole platform, set only a flag that says "A Control class was loaded already, so when platform starts, set the stylesheet" (if we're for some reason purposely only doing this when a Control class is loaded...)</p>
<p>I have no idea why this is in Control or PopupControl specifically.  If I make an FX application without ever loading Control (using Regions for example), should I be surprised that Modena styles are not working when I put them on my regions?  What if I do apply some style (let's say "button"), should I be surprised the behavior changes when I later do create (but not use) a Control as then suddenly Modena styles start applying?</p>
<p>Is there some attempt here to prevent loading of the Modena stylesheet when NOT using Controls?</p>
The code in question in Control static initializer is this:<br><br>
<div style="background-color: #ffffff; padding: 0.0px 0.0px 0.0px 2.0px;">
<div style="color: #000000; background-color: #ffffff; font-family: Consolas; font-size: 11.0pt; white-space: pre;">
<p style="margin: 0;"><span style="color: #000000;"> </span><span style="color: #3f7f5f;">// Ensures that the default application user agent stylesheet is loaded</span></p>
<p style="margin: 0;"><span style="color: #000000;"> </span><span style="color: #0000a0; font-weight: bold;">if</span><span style="color: #000000;"> (Application.</span><span style="color: #000000; font-style: italic;">getUserAgentStylesheet</span><span style="color: #000000;">() == </span><span style="color: #0000a0; font-weight: bold;">null</span><span style="color: #000000;">) {</span></p>
<p style="margin: 0;"><span style="color: #000000;"> PlatformImpl.</span><span style="color: #000000; background-color: #d4d4d4; font-style: italic;">setDefaultPlatformUserAgentStylesheet</span><span style="color: #000000;">();</span></p>
<p style="margin: 0;"><span style="color: #000000;"> }</span></p>
</div>
</div>
<p> </p>
<p>I really see no reason why this code needs to be here specifically.  It in fact looks a bit of a hack.</p>
<p>--John</p>
</div>