11/*
2- * Copyright (c) 2011, 2020 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2011, 2024 , 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
2626 * @key headful
2727 * @bug 4278839 8233634
2828 * @summary Incorrect cursor movement between words at the end of line
29- * @author Anton Nashatyrev
3029 * @library ../../../regtesthelpers
3130 * @build Util
3231 * @run main bug4278839
3332 */
3433
35- import java .awt .*;
36- import java .awt .event .*;
37- import javax .swing .*;
34+ import java .awt .Rectangle ;
35+ import java .awt .Robot ;
36+ import java .awt .event .KeyEvent ;
37+ import java .awt .event .InputEvent ;
38+ import javax .swing .JFrame ;
39+ import javax .swing .JScrollPane ;
40+ import javax .swing .JTextArea ;
41+ import javax .swing .SwingUtilities ;
42+ import javax .swing .UIManager ;
3843
39- public class bug4278839 extends JFrame {
44+ public class bug4278839 {
4045
4146 private static boolean passed = true ;
4247 private static JTextArea area ;
@@ -47,16 +52,12 @@ public static void main(String[] args) throws Exception {
4752 try {
4853
4954 robo = new Robot ();
50- robo .setAutoDelay (200 );
55+ robo .setAutoDelay (100 );
5156
52- SwingUtilities .invokeAndWait (new Runnable () {
53- @ Override
54- public void run () {
55- createAndShowGUI ();
56- }
57- });
57+ SwingUtilities .invokeAndWait (() -> createAndShowGUI ());
5858
5959 robo .waitForIdle ();
60+ robo .delay (1000 );
6061
6162 clickMouse ();
6263 robo .waitForIdle ();
@@ -100,33 +101,27 @@ private static int moveCaret(boolean right) throws Exception {
100101
101102 final int [] result = new int [1 ];
102103
103- SwingUtilities .invokeAndWait (new Runnable () {
104-
105- @ Override
106- public void run () {
107- result [0 ] = area .getCaretPosition ();
108- }
104+ SwingUtilities .invokeAndWait (() -> {
105+ result [0 ] = area .getCaretPosition ();
109106 });
110107
111- int pos = result [0 ];
112- return pos ;
108+ return result [0 ];
113109 }
114110
115111 private static void clickMouse () throws Exception {
116112 final Rectangle result [] = new Rectangle [1 ];
117113
118- SwingUtilities .invokeAndWait (new Runnable () {
119- @ Override
120- public void run () {
121- result [0 ] = new Rectangle (area .getLocationOnScreen (), area .getSize ());
122- }
114+ SwingUtilities .invokeAndWait (() -> {
115+ result [0 ] = new Rectangle (area .getLocationOnScreen (), area .getSize ());
123116 });
124117
125118 Rectangle rect = result [0 ];
126119
127120 robo .mouseMove (rect .x + rect .width / 2 , rect .y + rect .width / 2 );
128- robo .mousePress (InputEvent .BUTTON1_MASK );
129- robo .mouseRelease (InputEvent .BUTTON1_MASK );
121+ robo .waitForIdle ();
122+ robo .mousePress (InputEvent .BUTTON1_DOWN_MASK );
123+ robo .mouseRelease (InputEvent .BUTTON1_DOWN_MASK );
124+ robo .waitForIdle ();
130125 }
131126
132127 /**
0 commit comments