|
1 | 1 | /* |
2 | | - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2023, 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 |
|
26 | 26 | * @key headful |
27 | 27 | * @bug 7171812 |
28 | 28 | * @summary [macosx] Views keep scrolling back to the drag position after DnD |
29 | | - * @author Alexander Zuev |
30 | 29 | * @run main bug7171812 |
31 | 30 | */ |
32 | 31 |
|
33 | | -import java.awt.*; |
34 | | -import java.awt.dnd.*; |
| 32 | +import java.awt.BorderLayout; |
| 33 | +import java.awt.Point; |
| 34 | +import java.awt.Robot; |
| 35 | +import java.awt.dnd.DnDConstants; |
| 36 | +import java.awt.dnd.DropTarget; |
| 37 | +import java.awt.dnd.DropTargetDragEvent; |
| 38 | +import java.awt.dnd.DropTargetDropEvent; |
| 39 | +import java.awt.dnd.DropTargetEvent; |
| 40 | +import java.awt.dnd.DropTargetListener; |
35 | 41 | import java.awt.event.InputEvent; |
36 | | -import javax.swing.*; |
| 42 | +import javax.swing.JFrame; |
| 43 | +import javax.swing.JScrollPane; |
| 44 | +import javax.swing.SwingUtilities; |
37 | 45 |
|
38 | 46 | public class bug7171812 { |
39 | 47 | static JFrame mainFrame; |
40 | 48 | static String listData[]; |
41 | 49 | static JListWithScroll<String> list; |
42 | 50 | static JScrollPane scrollPane; |
| 51 | + static volatile Point pt; |
| 52 | + static volatile int height; |
43 | 53 |
|
44 | 54 | /** |
45 | 55 | * @param args the command line arguments |
46 | 56 | */ |
47 | 57 | public static void main(String[] args) throws Exception{ |
48 | 58 |
|
| 59 | + Robot robot = new Robot(); |
| 60 | + robot.setAutoDelay(100); |
| 61 | + robot.setAutoWaitForIdle(true); |
| 62 | + |
49 | 63 | SwingUtilities.invokeAndWait(new Runnable() { |
50 | 64 | @Override |
51 | 65 | public void run() { |
52 | 66 | setupGUI(); |
53 | 67 | } |
54 | 68 | }); |
55 | 69 |
|
56 | | - Robot robot = new Robot(); |
57 | | - robot.setAutoDelay(10); |
58 | 70 | robot.waitForIdle(); |
59 | | - robot.mouseMove(scrollPane.getLocationOnScreen().x + 5, scrollPane.getLocationOnScreen().y + 5); |
60 | | - robot.mousePress(InputEvent.BUTTON1_MASK); |
61 | | - for(int offset = 5; offset < scrollPane.getHeight()-20; offset++) { |
62 | | - robot.mouseMove(scrollPane.getLocationOnScreen().x+5, scrollPane.getLocationOnScreen().y+offset); |
| 71 | + robot.delay(1000); |
| 72 | + SwingUtilities.invokeAndWait(() -> { |
| 73 | + pt = scrollPane.getLocationOnScreen(); |
| 74 | + height = scrollPane.getHeight(); |
| 75 | + }); |
| 76 | + robot.mouseMove(pt.x + 5, pt.y + 5); |
| 77 | + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
| 78 | + for(int offset = 5; offset < height - 20; offset++) { |
| 79 | + robot.mouseMove(pt.x + 5, pt.y + offset); |
63 | 80 | } |
64 | 81 | for(int offset = 5; offset < 195; offset++) { |
65 | | - robot.mouseMove(scrollPane.getLocationOnScreen().x+offset, scrollPane.getLocationOnScreen().y+scrollPane.getHeight()-20); |
| 82 | + robot.mouseMove(pt.x + offset, pt.y + height - 20); |
66 | 83 | } |
67 | | - robot.mouseRelease(InputEvent.BUTTON1_MASK); |
| 84 | + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
68 | 85 | try { |
69 | 86 | SwingUtilities.invokeAndWait(new Runnable() { |
70 | 87 | @Override |
|
0 commit comments