Path: blob/master/test/jdk/javax/swing/JComboBox/7082443/bug7082443.java
41154 views
/*1* Copyright (c) 2011, 2018, 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)) {38try {39UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());40} catch (final UnsupportedLookAndFeelException ignored) {41continue;42}43SwingUtilities.invokeAndWait(new Runnable() {44@Override45public void run() {46TestComboBox testComboBox = new TestComboBox();4748if (testComboBox.isOldRendererOpaque()) {49System.out.println("Passed for " + GTK_LAF_CLASS);50} else {51throw new RuntimeException("Failed for " + GTK_LAF_CLASS);52}53}54});5556return;57}58}5960System.out.println(GTK_LAF_CLASS + " is not found. The test skipped");61}6263private static class TestComboBox extends JComboBox {64private final ListCellRenderer renderer = new ListCellRenderer() {65@Override66public Component getListCellRendererComponent(JList list, Object value, int index,67boolean isSelected, boolean cellHasFocus) {68return TestComboBox.super.getRenderer().getListCellRendererComponent(list, value, index,69isSelected, cellHasFocus);70}71};7273@Override74public ListCellRenderer getRenderer() {75return renderer;76}7778public boolean isOldRendererOpaque() {79return ((JLabel) super.getRenderer()).isOpaque();80}81}82}83848586