11/*
2- * Copyright (c) 2005, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2005, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2222 */
2323
2424import java .awt .BorderLayout ;
25- import java .awt .EventQueue ;
26- import java .awt .KeyboardFocusManager ;
2725import java .awt .Frame ;
26+ import java .awt .KeyboardFocusManager ;
2827import java .awt .List ;
2928import java .awt .Panel ;
3029import java .awt .Point ;
5150 * @run main KeyEventsTest
5251 */
5352public class KeyEventsTest {
54- TestState currentState ;
53+ private volatile TestState currentState ;
5554 final Object LOCK = new Object ();
5655 final int ACTION_TIMEOUT = 500 ;
5756
@@ -66,16 +65,14 @@ public static void main(final String[] args) throws Exception {
6665 r = new Robot ();
6766 KeyEventsTest app = new KeyEventsTest ();
6867 try {
69- EventQueue . invokeAndWait ( app :: initAndShowGui );
68+ app . initAndShowGui ( );
7069 r .waitForIdle ();
7170 r .delay (500 );
7271 app .doTest ();
7372 } finally {
74- EventQueue .invokeAndWait (() -> {
75- if (app .keyFrame != null ) {
76- app .keyFrame .dispose ();
77- }
78- });
73+ if (app .keyFrame != null ) {
74+ app .keyFrame .dispose ();
75+ }
7976 }
8077 }
8178
@@ -184,52 +181,51 @@ private void test(TestState currentState) throws Exception {
184181 throw new RuntimeException ("Test failed - list isn't focus owner." );
185182 }
186183
187- EventQueue .invokeAndWait (() -> {
188- list .deselect (0 );
189- list .deselect (1 );
190- list .deselect (2 );
191- list .deselect (3 );
192- list .deselect (4 );
193- list .deselect (5 );
194- list .deselect (6 );
195- list .deselect (7 );
196- list .deselect (8 );
197-
198- int selectIndex = 0 ;
199- int visibleIndex = 0 ;
200-
201- if (currentState .getScrollMoved ()) {
202- if (currentState .getKeyID () == KeyEvent .VK_PAGE_UP ||
203- currentState .getKeyID () == KeyEvent .VK_HOME ) {
204- selectIndex = 8 ;
205- visibleIndex = 8 ;
206- } else if (currentState .getKeyID () == KeyEvent .VK_PAGE_DOWN ||
207- currentState .getKeyID () == KeyEvent .VK_END ) {
184+ list .deselect (0 );
185+ list .deselect (1 );
186+ list .deselect (2 );
187+ list .deselect (3 );
188+ list .deselect (4 );
189+ list .deselect (5 );
190+ list .deselect (6 );
191+ list .deselect (7 );
192+ list .deselect (8 );
193+
194+ int selectIndex = 0 ;
195+ int visibleIndex = 0 ;
196+
197+ if (currentState .getScrollMoved ()) {
198+ if (currentState .getKeyID () == KeyEvent .VK_PAGE_UP ||
199+ currentState .getKeyID () == KeyEvent .VK_HOME ) {
200+ selectIndex = 8 ;
201+ visibleIndex = 8 ;
202+ } else if (currentState .getKeyID () == KeyEvent .VK_PAGE_DOWN ||
203+ currentState .getKeyID () == KeyEvent .VK_END ) {
204+ selectIndex = 0 ;
205+ visibleIndex = 0 ;
206+ }
207+ } else {
208+ if (currentState .getKeyID () == KeyEvent .VK_PAGE_UP ||
209+ currentState .getKeyID () == KeyEvent .VK_HOME ) {
210+ if (currentState .getSelectedMoved ()) {
211+ selectIndex = 1 ;
212+ } else {
208213 selectIndex = 0 ;
209- visibleIndex = 0 ;
210214 }
211- } else {
212- if (currentState .getKeyID () == KeyEvent .VK_PAGE_UP ||
213- currentState .getKeyID () == KeyEvent .VK_HOME ) {
214- if (currentState .getSelectedMoved ()) {
215- selectIndex = 1 ;
216- } else {
217- selectIndex = 0 ;
218- }
219- visibleIndex = 0 ;
220- } else if (currentState .getKeyID () == KeyEvent .VK_PAGE_DOWN ||
221- currentState .getKeyID () == KeyEvent .VK_END ) {
222- if (currentState .getSelectedMoved ()) {
223- selectIndex = 7 ;
224- } else {
225- selectIndex = 8 ;
226- }
227- visibleIndex = 8 ;
215+ visibleIndex = 0 ;
216+ } else if (currentState .getKeyID () == KeyEvent .VK_PAGE_DOWN ||
217+ currentState .getKeyID () == KeyEvent .VK_END ) {
218+ if (currentState .getSelectedMoved ()) {
219+ selectIndex = 7 ;
220+ } else {
221+ selectIndex = 8 ;
228222 }
223+ visibleIndex = 8 ;
229224 }
230- list .select (selectIndex );
231- list .makeVisible (visibleIndex );
232- });
225+ }
226+ list .select (selectIndex );
227+ list .makeVisible (visibleIndex );
228+
233229
234230 r .delay (10 );
235231 r .waitForIdle ();
@@ -309,7 +305,7 @@ class TestState {
309305 private final boolean scrollMoved ;
310306 private final int keyID ;
311307 private final boolean template ;
312- private boolean action ;
308+ private volatile boolean action ;
313309
314310 public TestState (boolean multiple , boolean selectedMoved , boolean scrollMoved , int keyID , boolean template ){
315311 this .multiple = multiple ;
0 commit comments