Test6888156.java revision 2365:4c234c13f66a
140525Sjdp/*
2324932Sbdrewery * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3199805Sattilio * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
440525Sjdp *
540525Sjdp * This code is free software; you can redistribute it and/or modify it
640525Sjdp * under the terms of the GNU General Public License version 2 only, as
740525Sjdp * published by the Free Software Foundation.
840525Sjdp *
940525Sjdp * This code is distributed in the hope that it will be useful, but WITHOUT
1040525Sjdp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1140525Sjdp * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1240525Sjdp * version 2 for more details (a copy is included in the LICENSE file that
1340525Sjdp * accompanied this code).
1440525Sjdp *
1540525Sjdp * You should have received a copy of the GNU General Public License version
1640525Sjdp * 2 along with this work; if not, write to the Free Software Foundation,
1740525Sjdp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1840525Sjdp *
1940525Sjdp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2040525Sjdp * or visit www.oracle.com if you need additional information or have any
2140525Sjdp * questions.
2240525Sjdp */
2340525Sjdp
2440525Sjdp/* @test
2540525Sjdp   @bug 6888156
2640525Sjdp   @summary Tests table column of class Icon.class with Synth LAF
2740525Sjdp   @author Peter Zhelezniakov
2840525Sjdp   @run main Test6888156
2993215Scharnier*/
3093215Scharnier
3193215Scharnierimport java.awt.Component;
32269128Smarcelimport java.awt.Graphics;
3340525Sjdpimport java.awt.image.BufferedImage;
3440525Sjdpimport javax.swing.*;
35199805Sattilioimport javax.swing.table.AbstractTableModel;
36103302Speterimport javax.swing.table.TableModel;
37103299Speter
38249687Strocinypublic class Test6888156 {
39199805Sattilio    private JTable table;
40199805Sattilio    private Icon ICON = new Icon() {
41199805Sattilio        @Override public int getIconWidth() {
4276224Sobrien            return 24;
4340525Sjdp        }
4440525Sjdp
4540525Sjdp        @Override public int getIconHeight() {
4640525Sjdp            return 24;
47249687Strociny        }
4840525Sjdp
4940525Sjdp        @Override public void paintIcon(Component c, Graphics g, int w, int h) {
5040525Sjdp        }
51274817Sjhb    };
52102951Siedowse
5340525Sjdp    public Test6888156() {
5440525Sjdp        TableModel model = new AbstractTableModel() {
5540525Sjdp            @Override public int getRowCount() {
5640525Sjdp                return 3;
57199805Sattilio            }
5840525Sjdp
5940525Sjdp            @Override public int getColumnCount() {
6040525Sjdp                return 2;
6140525Sjdp            }
6240525Sjdp
6340525Sjdp            @Override public Object getValueAt(int rowIndex, int columnIndex) {
6440525Sjdp                return (columnIndex == 1 ? ICON : 4);
6540525Sjdp            }
6640525Sjdp
6740525Sjdp            @Override public Class<?> getColumnClass(int columnIndex) {
6840525Sjdp                return (columnIndex == 1 ? Icon.class : int.class);
6940525Sjdp            }
7040525Sjdp        };
7140525Sjdp        table = new JTable(model);
7240525Sjdp    }
7340525Sjdp
7440525Sjdp    public void test(final LookAndFeel laf) throws Exception {
7540525Sjdp        SwingUtilities.invokeAndWait(new Runnable() {
7640525Sjdp            @Override public void run() {
7740525Sjdp                try {
7840525Sjdp                    UIManager.setLookAndFeel(laf);
79269128Smarcel                } catch (UnsupportedLookAndFeelException e) {
80269128Smarcel                    System.err.println(laf.getDescription() +
81269128Smarcel                                       " is unsupported; continuing");
82269128Smarcel                    return;
83269128Smarcel                }
84325029Sbdrewery                SwingUtilities.updateComponentTreeUI(table);
85269128Smarcel                table.setSize(100, 100);
86269128Smarcel                table.paint(
87325029Sbdrewery                        new BufferedImage(100, 100, BufferedImage.OPAQUE).
88325029Sbdrewery                            getGraphics());
89269128Smarcel            }
90269128Smarcel        });
91269128Smarcel    }
92269128Smarcel
93269128Smarcel    public static void main(String[] args) throws Exception {
94325029Sbdrewery        Test6888156 t = new Test6888156();
95269128Smarcel        t.test(new javax.swing.plaf.nimbus.NimbusLookAndFeel());
96269128Smarcel        t.test(new com.sun.java.swing.plaf.gtk.GTKLookAndFeel());
97325029Sbdrewery    }
98269128Smarcel}
99269128Smarcel
100249687Strociny