bug8017284.java revision 11018:66682f651425
1/*
2 * Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23import java.awt.BorderLayout;
24import java.awt.Toolkit;
25import java.awt.Robot;
26import javax.swing.JFrame;
27import javax.swing.JLabel;
28import javax.swing.JTabbedPane;
29import javax.swing.SwingUtilities;
30import javax.swing.plaf.metal.MetalLookAndFeel;
31
32/**
33 * @test
34 * @bug 8017284
35 * @author Alexander Scherbatiy
36 * @summary  Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles
37 * @run main/othervm/timeout=60 -Xmx128m bug8017284
38 */
39public class bug8017284 {
40
41    private static final int TAB_COUNT = 100;
42    private static final int ITERATIONS = 100;
43    private static JFrame frame;
44    private static JTabbedPane tabbedPane;
45
46    public static void main(String[] args) throws Exception {
47
48        Robot robot = new Robot();
49        SwingUtilities.invokeAndWait(() -> {
50            frame = new JFrame();
51            frame.setSize(500, 500);
52            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53
54            tabbedPane = new JTabbedPane();
55
56            for (int i = 0; i < TAB_COUNT; i++) {
57                tabbedPane.add("Header " + i, new JLabel("Content: " + i));
58            }
59
60            frame.getContentPane().setLayout(new BorderLayout());
61            frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
62            frame.setVisible(true);
63        });
64
65        robot.waitForIdle();
66
67        SwingUtilities.invokeAndWait(() -> {
68            for (int j = 0; j < ITERATIONS; j++) {
69                for (int i = 0; i < TAB_COUNT; i++) {
70                    tabbedPane.setTitleAt(i, getHtmlText(j * TAB_COUNT + i));
71                }
72            }
73        });
74        robot.waitForIdle();
75
76        SwingUtilities.invokeAndWait(() -> frame.dispose());
77    }
78
79    private static String getHtmlText(int i) {
80        return "<html><b><i>" + i + "</b></i>";
81    }
82}
83