StyleManager#reloadStylesheets(Scene) replacement in FX8

Tom Schindl tom.schindl at bestsolution.at
Thu Dec 6 07:21:00 PST 2012


Hi David,

Like I said, if i call e.g. clear on the old scene things work as
expected so for people who add/remove stuff from the same scene the
reloading is working.

So I'm not sure if you are really useing the wrong key, I assume it is
desired that the stylesheets are cached and reused on a scene base not?

The below example works like a charme:

> public class MyCSSReloadTest extends Application {
>
>     public static void main(String[] args) {
>         MyCSSReloadTest.launch(args);
>     }
>     
>     private Scene createScene(final Stage primaryStage) {
>         BorderPane p = new BorderPane();
>         final Scene s = new Scene(p,400,400);
>         final String stylesheet = MyCSSReloadTest.class.getResource("my.css").toExternalForm();
>         s.getStylesheets().add(stylesheet);
>         Button b = new Button("Reload "+  System.currentTimeMillis());
>         b.setOnAction(new EventHandler<ActionEvent>() {
>
>             @Override
>             public void handle(ActionEvent event) {
>                 s.getStylesheets().clear();
>                 s.getStylesheets().add(stylesheet);
>             }
>         });
>         p.setCenter(b);
>         return s;
>     }
>
>     @Override
>     public void start(Stage primaryStage) throws Exception {
>         primaryStage.setScene(createScene(primaryStage));
>         primaryStage.show();
>     }
>
> }

Tom

Am 06.12.12 16:08, schrieb David Grieve:
> There is a static map that keeps track of stylesheets that have been parsed. When a stylesheet is removed from the Scene's stylesheets, the corresponding map entry is supposed to be removed. If the stylesheet is added back in again it will be re-parsed since it is no longer in the map. The bug is in removing the stylesheet from the map. Apparently I'm not using the right key. 
> 
> On Dec 5, 2012, at 7:38 PM, Tom Schindl <tom.schindl at bestsolution.at> wrote:
> 
>> Hi David,
>>
>> Interesting I think my problem is very special because when ever I
>> reload my FXML-Preview I'm constructing a completely new scene and
>> simply set a new scene on the Stage (well in my case it is an FXCanvas
>> but that's not the real problem).
>>
>> I reduced the problem to the following:
>>
>>> public class MyCSSReloadTest extends Application {
>>>
>>>    public static void main(String[] args) {
>>>        MyCSSReloadTest.launch(args);
>>>    }
>>>
>>>    private Scene createScene(final Stage primaryStage) {
>>>        BorderPane p = new BorderPane();
>>>        final Scene s = new Scene(p,400,400);
>>>        final String stylesheet = MyCSSReloadTest.class.getResource("my.css").toExternalForm();
>>>        s.getStylesheets().add(stylesheet);
>>>        Button b = new Button("Reload "+  System.currentTimeMillis());
>>>        b.setOnAction(new EventHandler<ActionEvent>() {
>>>
>>>            @Override
>>>            public void handle(ActionEvent event) {
>>>                // s.getStylesheets().clear();
>>>                primaryStage.setScene(createScene(primaryStage));
>>>            }
>>>        });
>>>        p.setCenter(b);
>>>        return s;
>>>    }
>>>
>>>    @Override
>>>    public void start(Stage primaryStage) throws Exception {
>>>        primaryStage.setScene(createScene(primaryStage));
>>>        primaryStage.show();
>>>    }
>>>
>>> }
>>
>>
>> if you uncomment thje s.getStylesheets().clear() the reloading works as
>> expected. I'm not sure now if this is expected behavior for performance
>> optimization you are not parsing the CSS when it is already on another
>> although soon to be GC'ed scene.
>>
>> Tom
>>
>> Am 05.12.12 14:47, schrieb David Grieve:
>>> Must be a bug. The code is intended to re-parse a stylesheet if it has been removed and re-added to the Scene (or Parent) stylesheets. 
>>> If you would create a bug, I will fix it ASAP.
>>>
>>> On Dec 5, 2012, at 6:08 AM, Tom Schindl <tom.schindl at bestsolution.at> wrote:
>>>
>>>> Hi David,
>>>>
>>>> I tested with the latest JRE8 and unfortunately this is not working. The
>>>> CSS is only reloaded from the filesystem when the JVM is restarted, so
>>>> the same caching as in 2.x is happening.
>>>>
>>>> Tom
>>>>
>>>> Am 03.12.12 18:13, schrieb David Grieve:
>>>>> Remove and re-add the stylesheet.
>>>>>
>>>>> On Dec 1, 2012, at 9:41 AM, Tom Schindl <tom.schindl at bestsolution.at> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> To force reloading of stylesheets I used in FX2.2
>>>>>> StyleManager.getInstance().reloadStylesheets(scene). What is the
>>>>>> replacement of this in FX8.
>>>>>>
>>>>>> Tom
>>>>>>
>>>>>> -- 
>>>>>> B e s t S o l u t i o n . a t                        EDV Systemhaus GmbH
>>>>>> ------------------------------------------------------------------------
>>>>>> tom schindl                 geschäftsführer/CEO
>>>>>> ------------------------------------------------------------------------
>>>>>> eduard-bodem-gasse 5-7/1   A-6020 innsbruck     fax      ++43 512 935833
>>>>>> http://www.BestSolution.at                      phone    ++43 512 935834
>>>>>
>>>>
>>>>
>>>> -- 
>>>> B e s t S o l u t i o n . a t                        EDV Systemhaus GmbH
>>>> ------------------------------------------------------------------------
>>>> tom schindl                 geschäftsführer/CEO
>>>> ------------------------------------------------------------------------
>>>> eduard-bodem-gasse 5-7/1   A-6020 innsbruck     fax      ++43 512 935833
>>>> http://www.BestSolution.at                      phone    ++43 512 935834
>>>
>>
>>
>> -- 
>> B e s t S o l u t i o n . a t                        EDV Systemhaus GmbH
>> ------------------------------------------------------------------------
>> tom schindl                 geschäftsführer/CEO
>> ------------------------------------------------------------------------
>> eduard-bodem-gasse 5-7/1   A-6020 innsbruck     fax      ++43 512 935833
>> http://www.BestSolution.at                      phone    ++43 512 935834
> 


-- 
B e s t S o l u t i o n . a t                        EDV Systemhaus GmbH
------------------------------------------------------------------------
tom schindl                 geschäftsführer/CEO
------------------------------------------------------------------------
eduard-bodem-gasse 5-7/1   A-6020 innsbruck     fax      ++43 512 935833
http://www.BestSolution.at                      phone    ++43 512 935834


More information about the openjfx-dev mailing list