bug6416920.java revision 10730:07156012ab78
1/*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 6416920
27 * @summary Ensures that selected tab is painted properly in the scroll tab layout
28 *         under WindowsLookAndFeel in Windows' "Windows XP" theme.
29 * @author Mikhail Lapshin
30 * @library ../../../../lib/testlibrary
31 * @build jdk.testlibrary.OSInfo
32 * @run main bug6416920
33 */
34
35import javax.swing.plaf.basic.BasicTabbedPaneUI;
36import javax.swing.JTabbedPane;
37import javax.swing.SwingConstants;
38import java.awt.Rectangle;
39import java.awt.Insets;
40import jdk.testlibrary.OSInfo;
41
42public class bug6416920 extends BasicTabbedPaneUI {
43    public AccessibleTabbedPaneLayout layout = new AccessibleTabbedPaneLayout();
44
45    public static void main(String[] args) {
46
47        if(OSInfo.getOSType() != OSInfo.OSType.WINDOWS){
48            return;
49        }
50
51        bug6416920 test = new bug6416920();
52        test.layout.padSelectedTab(SwingConstants.TOP, 0);
53        if (test.rects[0].width < 0) {
54            throw new RuntimeException("A selected tab isn't painted properly " +
55                    "in the scroll tab layout under WindowsLookAndFeel " +
56                    "in Windows' \"Windows XP\" theme.");
57        }
58    }
59
60    public bug6416920() {
61        super();
62
63        // Set parameters for the padSelectedTab() method
64        selectedTabPadInsets = new Insets(0, 0, 0, 0);
65
66        tabPane = new JTabbedPane();
67        tabPane.setSize(100, 0);
68        tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
69
70        rects = new Rectangle[1];
71        rects[0] = new Rectangle(150, 0, 0, 0);
72    }
73
74    public class AccessibleTabbedPaneLayout extends BasicTabbedPaneUI.TabbedPaneLayout {
75        public void padSelectedTab(int tabPlacement, int selectedIndex) {
76            super.padSelectedTab(tabPlacement, selectedIndex);
77        }
78    }
79}
80