Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTabbedPane/7010561/bug7010561.java
38855 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@author Pavel Porvatov32*/33public class bug7010561 {34private static int[] TAB_PLACEMENT = {35SwingConstants.BOTTOM,36SwingConstants.BOTTOM,37SwingConstants.TOP,38SwingConstants.TOP,3940};4142private static boolean[] IS_SELECTED = {43false,44true,45false,46true47};4849private static int[] RETURN_VALUE = {50-1,511,521,53-154};5556public static void main(String[] args) throws Exception {57UIManager.setLookAndFeel(new SynthLookAndFeel());5859SwingUtilities.invokeAndWait(new Runnable() {60@Override61public void run() {62JTabbedPane tabbedPane = new JTabbedPane();6364tabbedPane.addTab("Tab 1", new JLabel("Tab 1"));6566// Ensure internal TabbedPane fields are initialized67tabbedPane.doLayout();6869BasicTabbedPaneUI basicTabbedPaneUI = (BasicTabbedPaneUI) tabbedPane.getUI();7071try {72Method method = BasicTabbedPaneUI.class.getDeclaredMethod("getTabLabelShiftY", int.class,73int.class, boolean.class);7475method.setAccessible(true);7677for (int i = 0; i < 4; i++) {78int res = ((Integer) method.invoke(basicTabbedPaneUI, TAB_PLACEMENT[i], 0,79IS_SELECTED[i])).intValue();8081if (res != RETURN_VALUE[i]) {82throw new RuntimeException("Test bug7010561 failed on index " + i);83}84}85} catch (Exception e) {86throw new RuntimeException(e);87}8889System.out.println("Test bug7010561 passed");90}91});92}93}949596