Path: blob/master/test/jdk/javax/swing/JTable/6567433/UpdateUIRecursionTest.java
41154 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 JTable.updateUI() invokes updateUI() on its TableCellrenderer via29* SwingUtilities.updateRendererOrEditorUI().30* If the TableCellrenderer is a parent of this JTable the method recurses31* endless.32* This test tests that the fix is effective in avoiding recursion.33*34* @run main/othervm UpdateUIRecursionTest35*/363738import java.awt.BorderLayout;39import java.awt.Component;40import javax.swing.JFrame;41import javax.swing.JScrollPane;42import javax.swing.JTable;43import javax.swing.SwingUtilities;44import javax.swing.table.DefaultTableCellRenderer;45import javax.swing.table.TableCellRenderer;4647public class UpdateUIRecursionTest extends JFrame implements TableCellRenderer {48JTable table;49DefaultTableCellRenderer renderer;5051public UpdateUIRecursionTest() {52super("UpdateUIRecursionTest");53setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);54setSize(400, 400);5556String[] columnNames = {57"First Name",58"Last Name",59"Sport",60"# of Years",61"Vegetarian"};6263Object[][] data = {64{"Mary", "Campione",65"Snowboarding", new Integer(5), new Boolean(false)},66{"Alison", "Huml",67"Rowing", new Integer(3), new Boolean(true)},68{"Kathy", "Walrath",69"Knitting", new Integer(2), new Boolean(false)},70{"Sharon", "Zakhour",71"Speed reading", new Integer(20), new Boolean(true)},72{"Philip", "Milne",73"Pool", new Integer(10), new Boolean(false)}74};757677table = new JTable(data, columnNames);7879renderer = new DefaultTableCellRenderer();80getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);81table.setDefaultRenderer(table.getColumnClass(1), this);8283setVisible(true);84}8586public static void main(String[] args) throws Exception {8788SwingUtilities.invokeAndWait(new Runnable() {8990@Override91public void run() {92UpdateUIRecursionTest obj = new UpdateUIRecursionTest();9394obj.test();9596obj.disposeUI();97}98});99}100101public void test() {102table.updateUI();103}104105public void disposeUI() {106setVisible(false);107dispose();108}109110@Override111public Component getTableCellRendererComponent(JTable table, Object value,112boolean isSelected, boolean hasFocus,113int row, int column)114{115return renderer.getTableCellRendererComponent(table, value, isSelected,116hasFocus, row, column);117}118}119120121