Path: blob/master/test/jdk/javax/swing/JComboBox/6567433/UpdateUIRecursionTest.java
41153 views
/*1* Copyright (c) 2016, 2017, 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/**24* @test25* @key headful26* @bug 656743327*28* @summary JComboBox.updateUI() invokes updateUI() on its cellrenderer via29* SwingUtilities.updateComponentTreeUI().30* If the cellrenderer is a parent of this JComboBox the method recurses31* endless.32* This test tests that the fix is effective in avoiding recursion.33*34* @run main/othervm UpdateUIRecursionTest35*/3637import java.awt.BorderLayout;38import java.awt.Component;39import javax.swing.DefaultListCellRenderer;40import javax.swing.JComboBox;41import javax.swing.JFrame;42import javax.swing.JList;43import javax.swing.JScrollPane;44import javax.swing.ListCellRenderer;45import javax.swing.SwingUtilities;4647public class UpdateUIRecursionTest extends JFrame implements ListCellRenderer {48JComboBox combo;49DefaultListCellRenderer renderer;5051public UpdateUIRecursionTest() {52super("UpdateUIRecursionTest");53setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);54setSize(400, 400);5556String[] listData = {57"First", "Second", "Third", "Fourth", "Fifth", "Sixth"58};5960combo = new JComboBox(listData);61combo.setRenderer(this);62renderer = new DefaultListCellRenderer();63getContentPane().add(new JScrollPane(combo), BorderLayout.CENTER);6465setVisible(true);66}6768public static void main(String[] args) throws Exception {6970SwingUtilities.invokeAndWait(new Runnable() {7172@Override73public void run() {74UpdateUIRecursionTest obj = new UpdateUIRecursionTest();7576obj.test();7778obj.disposeUI();79}80});81}8283public void test() {84combo.updateUI();85}8687public void disposeUI() {88setVisible(false);89dispose();90}9192public Component getListCellRendererComponent(JList list, Object value,93int index, boolean isSelected, boolean cellHasFocus)94{95return renderer.getListCellRendererComponent(list, value, index,96isSelected, cellHasFocus);97}98}99100101102