Test6919629.java revision 2337
2796N/A/*
3150N/A * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
2796N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2796N/A *
2796N/A * This code is free software; you can redistribute it and/or modify it
2796N/A * under the terms of the GNU General Public License version 2 only, as
2796N/A * published by the Free Software Foundation.
2796N/A *
2796N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2796N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2796N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2796N/A * version 2 for more details (a copy is included in the LICENSE file that
2796N/A * accompanied this code).
2796N/A *
2796N/A * You should have received a copy of the GNU General Public License version
2796N/A * 2 along with this work; if not, write to the Free Software Foundation,
2796N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2796N/A *
2796N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2796N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2796N/A * have any questions.
2796N/A */
2796N/A
2796N/A/* @test
2796N/A @bug 6919629
2796N/A @summary Tests that components with Nimbus.Overrides are GC'ed properly
2796N/A @author Peter Zhelezniakov
2796N/A @run main Test6919629
2796N/A*/
2796N/A
2796N/Aimport java.awt.Color;
2796N/Aimport java.lang.ref.WeakReference;
2796N/Aimport javax.swing.*;
2796N/Aimport javax.swing.plaf.nimbus.NimbusLookAndFeel;
2796N/A
2796N/Apublic class Test6919629
2796N/A{
2796N/A JFrame f;
2796N/A WeakReference<JLabel> ref;
2796N/A
2796N/A public static void main(String[] args) throws Exception {
2796N/A UIManager.setLookAndFeel(new NimbusLookAndFeel());
2796N/A Test6919629 t = new Test6919629();
2796N/A t.test();
2796N/A System.gc();
2796N/A t.check();
2796N/A }
2796N/A
2796N/A void test() throws Exception {
2796N/A SwingUtilities.invokeAndWait(new Runnable() {
2796N/A public void run() {
2796N/A UIDefaults d = new UIDefaults();
2796N/A d.put("Label.textForeground", Color.MAGENTA);
2796N/A
2796N/A JLabel l = new JLabel();
2796N/A ref = new WeakReference<JLabel>(l);
2796N/A l.putClientProperty("Nimbus.Overrides", d);
2796N/A
2796N/A f = new JFrame();
2796N/A f.getContentPane().add(l);
2796N/A f.pack();
2796N/A f.setVisible(true);
2796N/A }
2796N/A });
2796N/A Thread.sleep(2000);
2796N/A
2796N/A SwingUtilities.invokeAndWait(new Runnable() {
2796N/A public void run() {
2796N/A f.getContentPane().removeAll();
2796N/A f.setVisible(false);
2796N/A f.dispose();
2796N/A }
2796N/A });
2796N/A Thread.sleep(2000);
2796N/A }
2796N/A
2796N/A void check() {
2796N/A if (ref.get() != null) {
2796N/A throw new RuntimeException("Failed: an unused component wasn't collected");
2796N/A }
2796N/A }
2796N/A}
2796N/A