Skip to content

Commit 53ec75e

Browse files
committed
Refactor requestFocus
1 parent 776bd07 commit 53ec75e

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

  • toolkit-fx/src/main/java/com/techsenger/toolkit/fx/utils

toolkit-fx/src/main/java/com/techsenger/toolkit/fx/utils/NodeUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,28 @@ static void scrollToIfNeeded(VirtualFlow<?> flow, IntConsumer scroll, int index)
132132
}
133133

134134
private static void doRequestFocus(Node node, Runnable onSuccess, int maxAttempts) {
135+
int[] attempt = {0};
135136
Timeline[] holder = new Timeline[1];
136137
holder[0] = new Timeline(
137138
new KeyFrame(Duration.millis(25), e -> {
139+
var scene = node.getScene();
140+
if (scene == null) {
141+
holder[0].stop();
142+
return;
143+
}
138144
if (!node.isFocused()) {
145+
if (attempt[0] > 0) {
146+
logger.debug("Couldn't request focus for {}, after {} attempts; focus owner: {}",
147+
node, maxAttempts, scene.getFocusOwner());
148+
}
139149
node.requestFocus();
140150
} else {
141151
holder[0].stop();
142152
if (onSuccess != null) {
143153
onSuccess.run();
144154
}
145155
}
156+
attempt[0]++;
146157
})
147158
);
148159
holder[0].setCycleCount(maxAttempts);

0 commit comments

Comments
 (0)