Test6888156.java revision 1984:496c2f20dfac
1/* 2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 */ 23 24/* @test 25 @bug 6888156 26 @summary Tests table column of class Icon.class with Synth LAF 27 @author Peter Zhelezniakov 28 @run main Test6888156 29*/ 30 31import java.awt.Component; 32import java.awt.Graphics; 33import java.awt.image.BufferedImage; 34import javax.swing.*; 35import javax.swing.table.AbstractTableModel; 36import javax.swing.table.TableModel; 37 38public class Test6888156 { 39 private JTable table; 40 private Icon ICON = new Icon() { 41 @Override public int getIconWidth() { 42 return 24; 43 } 44 45 @Override public int getIconHeight() { 46 return 24; 47 } 48 49 @Override public void paintIcon(Component c, Graphics g, int w, int h) { 50 } 51 }; 52 53 public Test6888156() { 54 TableModel model = new AbstractTableModel() { 55 @Override public int getRowCount() { 56 return 3; 57 } 58 59 @Override public int getColumnCount() { 60 return 2; 61 } 62 63 @Override public Object getValueAt(int rowIndex, int columnIndex) { 64 return (columnIndex == 1 ? ICON : 4); 65 } 66 67 @Override public Class<?> getColumnClass(int columnIndex) { 68 return (columnIndex == 1 ? Icon.class : int.class); 69 } 70 }; 71 table = new JTable(model); 72 } 73 74 public void test(final LookAndFeel laf) throws Exception { 75 SwingUtilities.invokeAndWait(new Runnable() { 76 @Override public void run() { 77 try { 78 UIManager.setLookAndFeel(laf); 79 } catch (UnsupportedLookAndFeelException e) { 80 System.err.println(laf.getDescription() + 81 " is unsupported; continuing"); 82 return; 83 } 84 SwingUtilities.updateComponentTreeUI(table); 85 table.setSize(100, 100); 86 table.paint( 87 new BufferedImage(100, 100, BufferedImage.OPAQUE). 88 getGraphics()); 89 } 90 }); 91 } 92 93 public static void main(String[] args) throws Exception { 94 Test6888156 t = new Test6888156(); 95 t.test(new javax.swing.plaf.nimbus.NimbusLookAndFeel()); 96 t.test(new com.sun.java.swing.plaf.gtk.GTKLookAndFeel()); 97 } 98}