Path: blob/master/test/jdk/javax/swing/JScrollPane/bug8044371.java
41149 views
/*1* Copyright (c) 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*/2223/*24* @test25* @key headful26* @bug 804437127* @summary setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar28* @author Anton Nashatyrev29* @library ..30*/313233import javax.swing.*;34import javax.swing.plaf.metal.MetalLookAndFeel;35import java.awt.*;36import java.awt.event.AdjustmentEvent;37import java.awt.event.AdjustmentListener;3839public class bug8044371 implements AdjustmentListener {40JSplitPane sptPane;41int lastAdjust = 0;42int initialAdjust = 0;4344public static void main(String[] args) throws Throwable {45UIManager.setLookAndFeel(MetalLookAndFeel.class.getName());46SwingTest.start(bug8044371.class);47}4849public bug8044371(JFrame frame) {50JPanel p = new JPanel();51final JScrollPane jScrollPane = new JScrollPane(new JPanel()52{{setPreferredSize(new Dimension(1500,1500));}},53JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,54JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);55jScrollPane.getViewport().scrollRectToVisible(new Rectangle(1500, 1500, 0, 0));56jScrollPane.getVerticalScrollBar().addAdjustmentListener(this);5758sptPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jScrollPane, p);59sptPane.setDividerLocation(90);60sptPane.setOneTouchExpandable(true);61frame.getContentPane().add(sptPane);62}6364public void adjustmentValueChanged(AdjustmentEvent e) {65System.out.println( "adjustmentValueChanged: " + e.getValue());66lastAdjust = e.getValue();67}6869public void step1() {70if (lastAdjust == 0) {71throw new RuntimeException("Adjustment == 0");72}73initialAdjust = lastAdjust;74sptPane.setDividerLocation(0);75}7677public void step2() {78if (lastAdjust < initialAdjust) {79throw new RuntimeException("Failed: Adjustment decreased: " + lastAdjust);80}81sptPane.setDividerLocation(90);82}83public void step3() {84if (lastAdjust < initialAdjust) {85throw new RuntimeException("Failed: Adjustment decreased: " + lastAdjust);86}87}88}899091