Path: blob/master/test/jdk/javax/swing/JTabbedPane/7010561/bug7010561.java
41153 views
/*1* Copyright (c) 2012, 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*/2223import javax.swing.*;24import javax.swing.plaf.basic.BasicTabbedPaneUI;25import javax.swing.plaf.synth.SynthLookAndFeel;26import java.lang.reflect.Method;2728/* @test29@bug 701056130@summary Tab text position with Synth based LaF is different to Java 5/631@modules java.desktop/javax.swing.plaf.basic:open32@author Pavel Porvatov33*/34public class bug7010561 {35private static int[] TAB_PLACEMENT = {36SwingConstants.BOTTOM,37SwingConstants.BOTTOM,38SwingConstants.TOP,39SwingConstants.TOP,4041};4243private static boolean[] IS_SELECTED = {44false,45true,46false,47true48};4950private static int[] RETURN_VALUE = {51-1,521,531,54-155};5657public static void main(String[] args) throws Exception {58UIManager.setLookAndFeel(new SynthLookAndFeel());5960SwingUtilities.invokeAndWait(new Runnable() {61@Override62public void run() {63JTabbedPane tabbedPane = new JTabbedPane();6465tabbedPane.addTab("Tab 1", new JLabel("Tab 1"));6667// Ensure internal TabbedPane fields are initialized68tabbedPane.doLayout();6970BasicTabbedPaneUI basicTabbedPaneUI = (BasicTabbedPaneUI) tabbedPane.getUI();7172try {73Method method = BasicTabbedPaneUI.class.getDeclaredMethod("getTabLabelShiftY", int.class,74int.class, boolean.class);7576method.setAccessible(true);7778for (int i = 0; i < 4; i++) {79int res = ((Integer) method.invoke(basicTabbedPaneUI, TAB_PLACEMENT[i], 0,80IS_SELECTED[i])).intValue();8182if (res != RETURN_VALUE[i]) {83throw new RuntimeException("Test bug7010561 failed on index " + i);84}85}86} catch (Exception e) {87throw new RuntimeException(e);88}8990System.out.println("Test bug7010561 passed");91}92});93}94}959697