Path: blob/master/test/jdk/javax/swing/JTable/4235420/bug4235420.java
41153 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 {39for (UIManager.LookAndFeelInfo LF :40UIManager.getInstalledLookAndFeels()) {41try {42UIManager.setLookAndFeel(LF.getClassName());43} catch (UnsupportedLookAndFeelException ignored) {44System.out.println("Unsupported L&F: " + LF.getClassName());45} catch (ClassNotFoundException | InstantiationException46| IllegalAccessException e) {47throw new RuntimeException(e);48}49System.out.println("Testing L&F: " + LF.getClassName());5051if ("Nimbus".equals(UIManager.getLookAndFeel().getName()) ||52"GTK".equals(UIManager.getLookAndFeel().getName())) {53System.out.println("The test is skipped for Nimbus and GTK");5455continue;56}5758SwingUtilities.invokeAndWait(new Runnable() {59@Override60public void run() {61Table table = new Table();6263table.test();64}65});66}67}6869private static class Table extends JTable {70public void test() {71// Renderers72Class[] rendererClasses = {Object.class, Number.class, Date.class, ImageIcon.class, Boolean.class};7374Map copy = new HashMap(defaultRenderersByColumnClass);7576for (Class rendererClass : rendererClasses) {77Object obj = copy.get(rendererClass);7879if (obj instanceof TableCellRenderer) {80throw new Error("Failed: TableCellRenderer created for " +81rendererClass.getClass().getName());82}83}8485// Editors86Class[] editorClasses = {Object.class, Number.class, Boolean.class};8788copy = new HashMap(defaultEditorsByColumnClass);8990for (Class editorClass : editorClasses) {91Object obj = copy.get(editorClass);9293if (obj instanceof TableCellEditor) {94throw new Error("Failed: TableCellEditor created for " +95editorClass.getClass().getName());96}97}98}99}100}101102103