Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTable/4235420/bug4235420.java
38853 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*/2223/* @test24@bug 423542025@summary Tests that JTable delays creating Renderers and Editors26@author Peter Zhelezniakov27*/2829import javax.swing.*;30import javax.swing.table.TableCellEditor;31import javax.swing.table.TableCellRenderer;32import java.util.Date;33import java.util.HashMap;34import java.util.Map;3536public class bug4235420 {3738public static void main(String[] argv) throws Exception {39if ("Nimbus".equals(UIManager.getLookAndFeel().getName())) {40System.out.println("The test is skipped for Nimbus");4142return;43}4445SwingUtilities.invokeAndWait(new Runnable() {46@Override47public void run() {48Table table = new Table();4950table.test();51}52});53}5455private static class Table extends JTable {56public void test() {57// Renderers58Class[] rendererClasses = {Object.class, Number.class, Date.class, ImageIcon.class, Boolean.class};5960Map copy = new HashMap(defaultRenderersByColumnClass);6162for (Class rendererClass : rendererClasses) {63Object obj = copy.get(rendererClass);6465if (obj instanceof TableCellRenderer) {66throw new Error("Failed: TableCellRenderer created for " +67rendererClass.getClass().getName());68}69}7071// Editors72Class[] editorClasses = {Object.class, Number.class, Boolean.class};7374copy = new HashMap(defaultEditorsByColumnClass);7576for (Class editorClass : editorClasses) {77Object obj = copy.get(editorClass);7879if (obj instanceof TableCellEditor) {80throw new Error("Failed: TableCellEditor created for " +81editorClass.getClass().getName());82}83}84}85}86}878889