jdk/test/javax/swing/JScrollPane/bug8044371.java
author goetz
Tue, 09 Dec 2014 11:57:46 +0100
changeset 28187 fc19df82d6ee
parent 25567 93f3ca259c48
child 40128 e635645d2a8a
permissions -rw-r--r--
8066964: ppc64: argument and return type profiling, fix problem with popframe Reviewed-by: roland, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25567
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     1
/*
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     4
 *
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     7
 * published by the Free Software Foundation.
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     8
 *
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    13
 * accompanied this code).
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    14
 *
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    18
 *
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    21
 * questions.
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    22
 */
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    23
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    24
/*
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    25
 * @test
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    26
 * @bug 8044371
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    27
 * @summary setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    28
 * @author Anton Nashatyrev
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    29
 * @library ..
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    30
 */
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    31
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    32
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    33
import javax.swing.*;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    34
import javax.swing.plaf.metal.MetalLookAndFeel;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    35
import java.awt.*;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    36
import java.awt.event.AdjustmentEvent;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    37
import java.awt.event.AdjustmentListener;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    38
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    39
public class bug8044371 implements AdjustmentListener {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    40
    JSplitPane sptPane;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    41
    int lastAdjust = 0;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    42
    int initialAdjust = 0;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    43
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    44
    public static void main(String[] args) throws Throwable {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    45
        UIManager.setLookAndFeel(MetalLookAndFeel.class.getName());
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    46
        SwingTest.start(bug8044371.class);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    47
    }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    48
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    49
    public bug8044371(JFrame frame) {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    50
        JPanel p = new JPanel();
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    51
        final JScrollPane jScrollPane = new JScrollPane(new JPanel()
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    52
        {{setPreferredSize(new Dimension(1500,1500));}},
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    53
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    54
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    55
        jScrollPane.getViewport().scrollRectToVisible(new Rectangle(1500, 1500, 0, 0));
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    56
        jScrollPane.getVerticalScrollBar().addAdjustmentListener(this);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    57
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    58
        sptPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jScrollPane, p);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    59
        sptPane.setDividerLocation(90);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    60
        sptPane.setOneTouchExpandable(true);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    61
        frame.getContentPane().add(sptPane);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    62
    }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    63
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    64
    public void adjustmentValueChanged(AdjustmentEvent e) {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    65
        System.out.println( "adjustmentValueChanged: "  + e.getValue());
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    66
        lastAdjust = e.getValue();
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    67
    }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    68
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    69
    public void step1() {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    70
        if (lastAdjust == 0) {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    71
            throw new RuntimeException("Adjustment == 0");
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    72
        }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    73
        initialAdjust =  lastAdjust;
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    74
        sptPane.setDividerLocation(0);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    75
    }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    76
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    77
    public void step2() {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    78
        if (lastAdjust < initialAdjust) {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    79
            throw new RuntimeException("Failed: Adjustment decreased: " + lastAdjust);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    80
        }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    81
        sptPane.setDividerLocation(90);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    82
    }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    83
    public void step3() {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    84
        if (lastAdjust < initialAdjust) {
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    85
            throw new RuntimeException("Failed: Adjustment decreased: " + lastAdjust);
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    86
        }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    87
    }
93f3ca259c48 8044371: setOneTouchExpandable functionality of JSplitPane will reduce vertical Scrollbar
anashaty
parents:
diff changeset
    88
}