changeset 1984:496c2f20dfac

6888156: With GTK Look and Feel Icons cannot be rendered in Jtable Cells Reviewed-by: rupashka
author peterz
date Wed, 25 Nov 2009 20:47:20 +0300
parents 7bcb1864f424
children bb05c76b5c2f
files src/share/classes/javax/swing/JTable.java test/javax/swing/JTable/Test6888156.java
diffstat 2 files changed, 103 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/swing/JTable.java	Mon Nov 23 20:57:17 2009 +0300
+++ b/src/share/classes/javax/swing/JTable.java	Wed Nov 25 20:47:20 2009 +0300
@@ -1337,7 +1337,11 @@
                 return (TableCellRenderer)renderer;
             }
             else {
-                return getDefaultRenderer(columnClass.getSuperclass());
+                Class c = columnClass.getSuperclass();
+                if (c == null && columnClass != Object.class) {
+                    c = Object.class;
+                }
+                return getDefaultRenderer(c);
             }
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/JTable/Test6888156.java	Wed Nov 25 20:47:20 2009 +0300
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @bug 6888156
+   @summary Tests table column of class Icon.class with Synth LAF
+   @author Peter Zhelezniakov
+   @run main Test6888156
+*/
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
+import javax.swing.*;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableModel;
+
+public class Test6888156 {
+    private JTable table;
+    private Icon ICON = new Icon() {
+        @Override public int getIconWidth() {
+            return 24;
+        }
+
+        @Override public int getIconHeight() {
+            return 24;
+        }
+
+        @Override public void paintIcon(Component c, Graphics g, int w, int h) {
+        }
+    };
+
+    public Test6888156() {
+        TableModel model = new AbstractTableModel() {
+            @Override public int getRowCount() {
+                return 3;
+            }
+
+            @Override public int getColumnCount() {
+                return 2;
+            }
+
+            @Override public Object getValueAt(int rowIndex, int columnIndex) {
+                return (columnIndex == 1 ? ICON : 4);
+            }
+
+            @Override public Class<?> getColumnClass(int columnIndex) {
+                return (columnIndex == 1 ? Icon.class : int.class);
+            }
+        };
+        table = new JTable(model);
+    }
+
+    public void test(final LookAndFeel laf) throws Exception {
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override public void run() {
+                try {
+                    UIManager.setLookAndFeel(laf);
+                } catch (UnsupportedLookAndFeelException e) {
+                    System.err.println(laf.getDescription() +
+                                       " is unsupported; continuing");
+                    return;
+                }
+                SwingUtilities.updateComponentTreeUI(table);
+                table.setSize(100, 100);
+                table.paint(
+                        new BufferedImage(100, 100, BufferedImage.OPAQUE).
+                            getGraphics());
+            }
+        });
+    }
+
+    public static void main(String[] args) throws Exception {
+        Test6888156 t = new Test6888156();
+        t.test(new javax.swing.plaf.nimbus.NimbusLookAndFeel());
+        t.test(new com.sun.java.swing.plaf.gtk.GTKLookAndFeel());
+    }
+}
\ No newline at end of file