RFR: 8296621: Stage steals focus on scene change [v4]

Kevin Rushforth kcr at openjdk.org
Tue Dec 6 14:30:32 UTC 2022


On Tue, 6 Dec 2022 11:01:08 GMT, Thiago Milczarek Sayao <tsayao at openjdk.org> wrote:

>> tests/system/src/test/java/test/robot/javafx/scene/SceneChangeShouldNotFocusStageTest.java line 80:
>> 
>>> 78:             tl.setCycleCount(Animation.INDEFINITE);
>>> 79:             tl.getKeyFrames().addAll(new KeyFrame(Duration.millis(0), e -> stage.setScene(scene1)),
>>> 80:                     new KeyFrame(Duration.millis(200), e -> stage.setScene(scene2)));
>> 
>> With `Duration.millis(0)`, JavaFX gets no time to switch to `scene2`. We should allow some time for `stage.setScene(scene2)` to be processed.
>> We can observe the behavior by commenting two lines 55 and 88, and adding a delay `Util.sleep(10000)` in `exit()` method : The `scene2` will never be seen on Window.
>> I would recommend to change `Duration.millis(0)` to `Duration.millis(100)` OR any other duration with sufficient gap between the two Frames.
>
> I don't mind changing it, but I think those durations are relative, so `Duration.millis(0)` means "don't wait". I'm not sure I follow the recommendation.

To expand on what Ambarish said, if you have a repeating timeline, any action that is done as part of a `KeyFrame` at time 0 will be executed immediately (with no delay) after an action that is done as part of the `KeyFrame` at time `last`. So in the current test (which mimics the manual test program submitted with the bug), what you have is:


set scene 1
wait 200 msec
set scene 2
set scene 1 // immediately after the previous
wait 200 msec
...


To do what you want, you might add a third "no-op" `KeyFrame` at time 400 (you could also change the time values for the two existing `KeyFrame`s to 200 and 400, respectively, but then no scene would be set for the first 200 msec of the test when the timeline first plays).

-------------

PR: https://git.openjdk.org/jfx/pull/940


More information about the openjfx-dev mailing list