Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JList/6510999/bug6510999.java
41155 views
1
/*
2
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
/*
24
* @test
25
* @key headful
26
* @bug 6510999
27
* @summary Selection in a JList with both scrollbars visible jumps on arrowkey-down
28
* @author Alexander Potochkin
29
* @run main bug6510999
30
*/
31
32
import javax.swing.*;
33
import java.awt.*;
34
import java.awt.event.KeyEvent;
35
36
public class bug6510999 {
37
private static JScrollPane s;
38
static JFrame frame;
39
40
private static void createGui() {
41
frame = new JFrame();
42
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
43
44
DefaultListModel dlm = new DefaultListModel();
45
for (int i = 0; i < 100; i++)
46
dlm
47
.addElement(i + " listItemlistItemlistItemlistItemItem");
48
JList l = new JList();
49
l.setModel(dlm);
50
s = new JScrollPane(l);
51
l.setSelectedIndex(50);
52
l.ensureIndexIsVisible(50);
53
54
frame.add(s);
55
frame.setSize(200, 200);
56
frame.setLocationRelativeTo(null);
57
frame.setVisible(true);
58
}
59
60
public static void main(String[] args) throws Exception {
61
try {
62
Robot robot = new Robot();
63
robot.setAutoDelay(10);
64
SwingUtilities.invokeAndWait(new Runnable() {
65
public void run() {
66
bug6510999.createGui();
67
}
68
});
69
robot.waitForIdle();
70
Point viewPosition = s.getViewport().getViewPosition();
71
robot.keyPress(KeyEvent.VK_DOWN);
72
robot.keyRelease(KeyEvent.VK_DOWN);
73
robot.waitForIdle();
74
if (!s.getViewport().getViewPosition().equals(viewPosition)) {
75
throw new RuntimeException("JScrollPane was unexpectedly scrolled");
76
}
77
} finally {
78
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
79
}
80
}
81
}
82
83