Path: blob/master/test/jdk/javax/swing/JTabbedPane/8017284/bug8017284.java
41155 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.awt.BorderLayout;23import java.awt.Toolkit;24import java.awt.Robot;25import javax.swing.JFrame;26import javax.swing.JLabel;27import javax.swing.JTabbedPane;28import javax.swing.SwingUtilities;29import javax.swing.plaf.metal.MetalLookAndFeel;3031/**32* @test33* @key headful34* @bug 801728435* @author Alexander Scherbatiy36* @summary Aqua LaF: memory leak when HTML is used for JTabbedPane tab titles37* @run main/othervm/timeout=60 -Xmx128m bug801728438*/39public class bug8017284 {4041private static final int TAB_COUNT = 100;42private static final int ITERATIONS = 100;43private static JFrame frame;44private static JTabbedPane tabbedPane;4546public static void main(String[] args) throws Exception {4748Robot robot = new Robot();49SwingUtilities.invokeAndWait(() -> {50frame = new JFrame();51frame.setSize(500, 500);52frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);5354tabbedPane = new JTabbedPane();5556for (int i = 0; i < TAB_COUNT; i++) {57tabbedPane.add("Header " + i, new JLabel("Content: " + i));58}5960frame.getContentPane().setLayout(new BorderLayout());61frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);62frame.setVisible(true);63});6465robot.waitForIdle();6667SwingUtilities.invokeAndWait(() -> {68for (int j = 0; j < ITERATIONS; j++) {69for (int i = 0; i < TAB_COUNT; i++) {70tabbedPane.setTitleAt(i, getHtmlText(j * TAB_COUNT + i));71}72}73});74robot.waitForIdle();7576SwingUtilities.invokeAndWait(() -> frame.dispose());77}7879private static String getHtmlText(int i) {80return "<html><b><i>" + i + "</b></i>";81}82}838485