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
2424/*
2525 * @test
2626 * @bug 6240151
27+ * @key headful
2728 * @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
3131*/
3232
33+ import java .awt .EventQueue ;
3334import java .awt .FlowLayout ;
3435import java .awt .Frame ;
3536import 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 ;
3740import java .awt .event .MouseAdapter ;
3841import java .awt .event .MouseEvent ;
42+ import java .awt .event .MouseMotionAdapter ;
3943
4044public 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 ;
4650
4751 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+ }
5762 }
5863
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 );
6267
6368 list .add ("000" );
6469 list .add ("111" );
@@ -77,27 +82,52 @@ private static Frame createTestUI() {
7782 new MouseMotionAdapter (){
7883 @ Override
7984 public void mouseDragged (MouseEvent me ){
80- PassFailJFrame .log (me .toString ());
85+ System .out .println (me );
86+ throw new RuntimeException ("Mouse dragged event detected." );
8187 }
8288 });
8389
8490 list .addMouseListener (
8591 new MouseAdapter () {
8692 public void mousePressed (MouseEvent me ) {
87- PassFailJFrame .log (me .toString ());
93+ System .out .println (me );
94+ throw new RuntimeException ("Mouse pressed event detected." );
8895 }
8996
9097 public void mouseReleased (MouseEvent me ) {
91- PassFailJFrame .log (me .toString ());
98+ System .out .println (me );
99+ throw new RuntimeException ("Mouse released event detected." );
92100 }
93101
94102 public void mouseClicked (MouseEvent me ){
95- PassFailJFrame .log (me .toString ());
103+ System .out .println (me );
104+ throw new RuntimeException ("Mouse clicked event detected." );
96105 }
97106 });
98107
99108 frame .setLayout (new FlowLayout ());
100109 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 );
102132 }
103133}
0 commit comments