1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
24
24
/*
25
25
* @test
26
26
* @bug 6240151
27
+ * @key headful
27
28
* @summary XToolkit: Dragging the List scrollbar initiates DnD
28
- * @library /java/awt/regtesthelpers
29
- * @build PassFailJFrame
30
- * @run main/manual MouseDraggedOriginatedByScrollBarTest
29
+ * @requires os.family == "linux"
30
+ * @run main MouseDraggedOriginatedByScrollBarTest
31
31
*/
32
32
33
+ import java .awt .EventQueue ;
33
34
import java .awt .FlowLayout ;
34
35
import java .awt .Frame ;
35
36
import java .awt .List ;
36
- import java .awt .event .MouseMotionAdapter ;
37
+ import java .awt .Point ;
38
+ import java .awt .Robot ;
39
+ import java .awt .event .InputEvent ;
37
40
import java .awt .event .MouseAdapter ;
38
41
import java .awt .event .MouseEvent ;
42
+ import java .awt .event .MouseMotionAdapter ;
39
43
40
44
public class MouseDraggedOriginatedByScrollBarTest {
41
-
42
- private static final String INSTRUCTIONS = """
43
- 1) Click and drag the scrollbar of the list.
44
- 2) Keep dragging till the mouse pointer goes out the scrollbar.
45
- 3) The test failed if you see messages about events. The test passed if you don't.""" ;
45
+ private static Frame frame ;
46
+ private static volatile Point loc ;
47
+ private static List list ;
48
+ private static final int XOFFSET = 10 ;
49
+ private static final int YOFFSET = 20 ;
46
50
47
51
public static void main (String [] args ) throws Exception {
48
- PassFailJFrame .builder ()
49
- .title ("MouseDraggedOriginatedByScrollBarTest Instructions" )
50
- .instructions (INSTRUCTIONS )
51
- .rows ((int ) INSTRUCTIONS .lines ().count () + 2 )
52
- .columns (35 )
53
- .testUI (MouseDraggedOriginatedByScrollBarTest ::createTestUI )
54
- .logArea ()
55
- .build ()
56
- .awaitAndCheck ();
52
+ try {
53
+ EventQueue .invokeAndWait (() -> createUI ());
54
+ test ();
55
+ } finally {
56
+ EventQueue .invokeAndWait (() -> {
57
+ if (frame != null ) {
58
+ frame .dispose ();
59
+ }
60
+ });
61
+ }
57
62
}
58
63
59
- private static Frame createTestUI () {
60
- Frame frame = new Frame ();
61
- List list = new List (4 , false );
64
+ private static void createUI () {
65
+ frame = new Frame ();
66
+ list = new List (4 , false );
62
67
63
68
list .add ("000" );
64
69
list .add ("111" );
@@ -77,27 +82,52 @@ private static Frame createTestUI() {
77
82
new MouseMotionAdapter (){
78
83
@ Override
79
84
public void mouseDragged (MouseEvent me ){
80
- PassFailJFrame .log (me .toString ());
85
+ System .out .println (me );
86
+ throw new RuntimeException ("Mouse dragged event detected." );
81
87
}
82
88
});
83
89
84
90
list .addMouseListener (
85
91
new MouseAdapter () {
86
92
public void mousePressed (MouseEvent me ) {
87
- PassFailJFrame .log (me .toString ());
93
+ System .out .println (me );
94
+ throw new RuntimeException ("Mouse pressed event detected." );
88
95
}
89
96
90
97
public void mouseReleased (MouseEvent me ) {
91
- PassFailJFrame .log (me .toString ());
98
+ System .out .println (me );
99
+ throw new RuntimeException ("Mouse released event detected." );
92
100
}
93
101
94
102
public void mouseClicked (MouseEvent me ){
95
- PassFailJFrame .log (me .toString ());
103
+ System .out .println (me );
104
+ throw new RuntimeException ("Mouse clicked event detected." );
96
105
}
97
106
});
98
107
99
108
frame .setLayout (new FlowLayout ());
100
109
frame .pack ();
101
- return frame ;
110
+ frame .setLocationRelativeTo (null );
111
+ frame .setVisible (true );
112
+ }
113
+
114
+ private static void test () throws Exception {
115
+ Robot robot = new Robot ();
116
+ robot .waitForIdle ();
117
+ robot .delay (1000 );
118
+ robot .setAutoWaitForIdle (true );
119
+
120
+ EventQueue .invokeAndWait (() -> {
121
+ Point p = list .getLocationOnScreen ();
122
+ p .translate (list .getWidth () - XOFFSET , YOFFSET );
123
+ loc = p ;
124
+ });
125
+ robot .mouseMove (loc .x , loc .y );
126
+ robot .mousePress (InputEvent .BUTTON1_DOWN_MASK );
127
+ for (int i = 0 ; i < 30 ; i ++) {
128
+ robot .mouseMove (loc .x , loc .y + i );
129
+ }
130
+ robot .mouseRelease (InputEvent .BUTTON1_DOWN_MASK );
131
+ robot .delay (100 );
102
132
}
103
133
}
0 commit comments