Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JComboBox/7082443/bug7082443.java
38853 views
/*1* Copyright (c) 2011, 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*/2223/* @test24* @bug 708244325* @summary JComboBox not backward compatible (with Java 6)26* @author Pavel Porvatov27*/2829import javax.swing.*;30import java.awt.*;3132public class bug7082443 {33public static final String GTK_LAF_CLASS = "GTKLookAndFeel";3435public static void main(String[] args) throws Exception {36for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {37if (lookAndFeelInfo.getClassName().contains(GTK_LAF_CLASS)) {38UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());3940SwingUtilities.invokeAndWait(new Runnable() {41@Override42public void run() {43TestComboBox testComboBox = new TestComboBox();4445if (testComboBox.isOldRendererOpaque()) {46System.out.println("Passed for " + GTK_LAF_CLASS);47} else {48throw new RuntimeException("Failed for " + GTK_LAF_CLASS);49}50}51});5253return;54}55}5657System.out.println(GTK_LAF_CLASS + " is not found. The test skipped");58}5960private static class TestComboBox extends JComboBox {61private final ListCellRenderer renderer = new ListCellRenderer() {62@Override63public Component getListCellRendererComponent(JList list, Object value, int index,64boolean isSelected, boolean cellHasFocus) {65return TestComboBox.super.getRenderer().getListCellRendererComponent(list, value, index,66isSelected, cellHasFocus);67}68};6970@Override71public ListCellRenderer getRenderer() {72return renderer;73}7475public boolean isOldRendererOpaque() {76return ((JLabel) super.getRenderer()).isOpaque();77}78}79}80818283