Path: blob/master/test/jdk/javax/swing/JList/6510999/bug6510999.java
41155 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/*23* @test24* @key headful25* @bug 651099926* @summary Selection in a JList with both scrollbars visible jumps on arrowkey-down27* @author Alexander Potochkin28* @run main bug651099929*/3031import javax.swing.*;32import java.awt.*;33import java.awt.event.KeyEvent;3435public class bug6510999 {36private static JScrollPane s;37static JFrame frame;3839private static void createGui() {40frame = new JFrame();41frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4243DefaultListModel dlm = new DefaultListModel();44for (int i = 0; i < 100; i++)45dlm46.addElement(i + " listItemlistItemlistItemlistItemItem");47JList l = new JList();48l.setModel(dlm);49s = new JScrollPane(l);50l.setSelectedIndex(50);51l.ensureIndexIsVisible(50);5253frame.add(s);54frame.setSize(200, 200);55frame.setLocationRelativeTo(null);56frame.setVisible(true);57}5859public static void main(String[] args) throws Exception {60try {61Robot robot = new Robot();62robot.setAutoDelay(10);63SwingUtilities.invokeAndWait(new Runnable() {64public void run() {65bug6510999.createGui();66}67});68robot.waitForIdle();69Point viewPosition = s.getViewport().getViewPosition();70robot.keyPress(KeyEvent.VK_DOWN);71robot.keyRelease(KeyEvent.VK_DOWN);72robot.waitForIdle();73if (!s.getViewport().getViewPosition().equals(viewPosition)) {74throw new RuntimeException("JScrollPane was unexpectedly scrolled");75}76} finally {77if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());78}79}80}818283