Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JList/6510999/bug6510999.java
38854 views
/*1* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/* @test23@bug 651099924@summary Selection in a JList with both scrollbars visible jumps on arrowkey-down25@author Alexander Potochkin26@run main bug651099927*/2829import javax.swing.*;30import java.awt.*;31import java.awt.event.KeyEvent;3233public class bug6510999 {34private static JScrollPane s;3536private static void createGui() {37final JFrame frame = new JFrame();38frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);3940DefaultListModel dlm = new DefaultListModel();41for (int i = 0; i < 100; i++)42dlm43.addElement(i + " listItemlistItemlistItemlistItemItem");44JList l = new JList();45l.setModel(dlm);46s = new JScrollPane(l);47l.setSelectedIndex(50);48l.ensureIndexIsVisible(50);4950frame.add(s);51frame.setSize(200, 200);52frame.setLocationRelativeTo(null);53frame.setVisible(true);54}5556public static void main(String[] args) throws Exception {57Robot robot = new Robot();58robot.setAutoDelay(10);59SwingUtilities.invokeAndWait(new Runnable() {60public void run() {61bug6510999.createGui();62}63});64robot.waitForIdle();65Point viewPosition = s.getViewport().getViewPosition();66robot.keyPress(KeyEvent.VK_DOWN);67robot.keyRelease(KeyEvent.VK_DOWN);68robot.waitForIdle();69if (!s.getViewport().getViewPosition().equals(viewPosition)) {70throw new RuntimeException("JScrollPane was unexpectedly scrolled");71}72}73}747576