bug7010561.java revision 4612
0N/A/*
1121N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.plaf.basic.BasicTabbedPaneUI;
0N/Aimport javax.swing.plaf.synth.SynthLookAndFeel;
0N/Aimport java.lang.reflect.Method;
0N/A
0N/A/* @test
0N/A @bug 7010561
0N/A @summary Tab text position with Synth based LaF is different to Java 5/6
0N/A @author Pavel Porvatov
0N/A*/
0N/Apublic class bug7010561 {
0N/A private static int[] TAB_PLACEMENT = {
0N/A SwingConstants.BOTTOM,
0N/A SwingConstants.BOTTOM,
0N/A SwingConstants.TOP,
0N/A SwingConstants.TOP,
0N/A
0N/A };
0N/A
0N/A private static boolean[] IS_SELECTED = {
0N/A false,
0N/A true,
0N/A false,
0N/A true
0N/A };
0N/A
0N/A private static int[] RETURN_VALUE = {
0N/A -1,
0N/A 1,
0N/A 1,
0N/A -1
0N/A };
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A UIManager.setLookAndFeel(new SynthLookAndFeel());
0N/A
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A @Override
0N/A public void run() {
0N/A JTabbedPane tabbedPane = new JTabbedPane();
0N/A
0N/A tabbedPane.addTab("Tab 1", new JLabel("Tab 1"));
0N/A
0N/A // Ensure internal TabbedPane fields are initialized
0N/A tabbedPane.doLayout();
0N/A
0N/A BasicTabbedPaneUI basicTabbedPaneUI = (BasicTabbedPaneUI) tabbedPane.getUI();
0N/A
0N/A try {
0N/A Method method = BasicTabbedPaneUI.class.getDeclaredMethod("getTabLabelShiftY", int.class,
0N/A int.class, boolean.class);
0N/A
0N/A method.setAccessible(true);
0N/A
0N/A for (int i = 0; i < 4; i++) {
0N/A int res = ((Integer) method.invoke(basicTabbedPaneUI, TAB_PLACEMENT[i], 0,
0N/A IS_SELECTED[i])).intValue();
0N/A
0N/A if (res != RETURN_VALUE[i]) {
0N/A throw new RuntimeException("Test bug7010561 failed on index " + i);
0N/A }
0N/A }
0N/A } catch (Exception e) {
0N/A throw new RuntimeException(e);
0N/A }
0N/A
0N/A System.out.println("Test bug7010561 passed");
0N/A }
0N/A });
0N/A }
0N/A}
0N/A