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