Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JSplitPane/4816114/bug4816114.java
38854 views
/*1* Copyright (c) 2013, 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 481611424@summary REGRESSION: Regression in divider location behavior when JSplitPane is resized25@author Andrey Pikalev26@run main bug481611427*/2829import javax.swing.*;30import java.awt.*;31import java.lang.reflect.*;323334public class bug4816114 {3536JFrame fr;37JSplitPane splitPane;3839boolean[] resized = new boolean[] { false, false, false,40false, false, false };41static int step = 0;42boolean h_passed = false;43boolean v_passed = false;4445static bug4816114 test = new bug4816114();4647public static void main(String[] args) throws InterruptedException, InvocationTargetException, AWTException {48SwingUtilities.invokeAndWait(new Runnable() {49public void run() {50test.createAndShowGUI();51}52});53Robot robot = new Robot();54robot.waitForIdle();55Thread.sleep(1000);56Thread.sleep(2000);5758step++;59test.doTest(150, 300);6061step++;62test.doTest(650, 300);6364SwingUtilities.invokeAndWait(new Runnable() {65public void run() {66test.splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);67}68});6970step++;71test.doTest(300, 650);7273step++;74test.doTest(300, 150);7576step++;77test.doTest(300, 650);7879if ( !test.isPassed() ) {80throw new Error("The divider location is wrong.");81}82}83public void createAndShowGUI() {84fr = new JFrame("Test");8586splitPane = new TestSplitPane();87splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);88splitPane.setResizeWeight(0);89splitPane.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));9091JButton leftButton = new JButton("LEFT");92leftButton.setPreferredSize(new Dimension(300, 300));93leftButton.setMinimumSize(new Dimension(150, 150));94splitPane.setLeftComponent(leftButton);9596JButton rightButton = new JButton("RIGHT");97rightButton.setPreferredSize(new Dimension(300, 300));98rightButton.setMinimumSize(new Dimension(150, 150));99splitPane.setRightComponent(rightButton);100101fr.getContentPane().add(splitPane, BorderLayout.CENTER);102103fr.pack();104fr.setVisible(true);105}106107void doTest(final int width, final int height) throws InterruptedException, InvocationTargetException {108SwingUtilities.invokeAndWait(new Runnable() {109public void run() {110splitPane.setPreferredSize(new Dimension(width, height));111fr.pack();112}113});114115synchronized (bug4816114.this) {116while (!resized[step]) {117bug4816114.this.wait();118}119}120}121122synchronized void setPassed(int orientation, boolean passed) {123if (orientation == JSplitPane.HORIZONTAL_SPLIT) {124this.h_passed = passed;125}126else {127this.v_passed = passed;128}129}130131synchronized boolean isPassed() {132return h_passed && v_passed;133}134135136class TestSplitPane extends JSplitPane {137public void setDividerLocation(int location) {138super.setDividerLocation(location);139140if ( splitPane.getDividerLocation() == 151 ) {141setPassed(getOrientation(), true);142}143144synchronized (bug4816114.this) {145resized[step] = true;146bug4816114.this.notifyAll();147}148}149}150}151152153