Skip to content

Commit

Permalink
8090647: Mnemonics : on windows we should cancel the underscore latch…
Browse files Browse the repository at this point in the history
… when an app loses focus.

Reviewed-by: angorya, aghaisas
  • Loading branch information
hjohn committed Feb 22, 2023
1 parent 315939f commit 25e4ab9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/javafx.graphics/src/main/java/javafx/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,10 @@ private void setWindowFocused(boolean value) {
if (windowFocused && accessible != null) {
accessible.sendNotification(AccessibleAttribute.FOCUS_NODE);
}

if (!windowFocused) {
getInternalEventDispatcher().getKeyboardShortcutsHandler().setMnemonicsDisplayEnabled(false);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

package test.javafx.scene;

import com.sun.javafx.scene.KeyboardShortcutsHandler;
import com.sun.javafx.scene.NodeHelper;
import com.sun.javafx.scene.SceneEventDispatcher;
import com.sun.javafx.scene.SceneHelper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -1065,4 +1067,29 @@ public void testAddNullPostLayoutPulseListener() {

JMemoryBuddy.assertCollectable(ref);
}

@Test
public void sceneShouldSet_MnemonicsDisplayEnabled_ToFalseWhenWindowFocusIsLost() {
Group root = new Group();

root.setFocusTraversable(true);

Scene scene = new Scene(root);
SceneEventDispatcher dispatcher = (SceneEventDispatcher) scene.getEventDispatcher();
KeyboardShortcutsHandler keyboardShortcutsHandler = dispatcher.getKeyboardShortcutsHandler();

stage.setScene(scene);
stage.show();
stage.requestFocus();

assertFalse(keyboardShortcutsHandler.isMnemonicsDisplayEnabled());

keyboardShortcutsHandler.setMnemonicsDisplayEnabled(true);

assertTrue(keyboardShortcutsHandler.isMnemonicsDisplayEnabled());

stage.close();

assertFalse(keyboardShortcutsHandler.isMnemonicsDisplayEnabled());
}
}

1 comment on commit 25e4ab9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.