1/*
2 * Copyright (c) 2012, 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 */
23
24
25/*
26 * @test
27 * @bug 4314199
28 * @summary Tests that JTree repaints correctly in a container with a JMenu
29 * @author Peter Zhelezniakov
30 * @run applet/manual=yesno bug4314199.html
31 */
32
33import javax.swing.*;
34import javax.swing.tree.*;
35
36public class bug4314199 extends JApplet {
37
38    public void init() {
39
40        try {
41            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
42            SwingUtilities.invokeAndWait(new Runnable() {
43
44                public void run() {
45                    createAndShowGUI();
46                }
47            });
48        } catch (final Exception e) {
49            SwingUtilities.invokeLater(new Runnable() {
50
51                public void run() {
52                    createAndShowMessage("Test fails because of exception: "
53                            + e.getMessage());
54                }
55            });
56        }
57
58    }
59
60    private void createAndShowMessage(String message) {
61        getContentPane().add(new JLabel(message));
62    }
63
64    private void createAndShowGUI() {
65        JMenuBar mb = new JMenuBar();
66
67        // needed to exactly align left edge of menu and angled line of tree
68        mb.add(Box.createHorizontalStrut(27));
69
70        JMenu mn = new JMenu("Menu");
71        JMenuItem mi = new JMenuItem("MenuItem");
72        mn.add(mi);
73        mb.add(mn);
74        setJMenuBar(mb);
75
76        DefaultMutableTreeNode n1 = new DefaultMutableTreeNode("Root");
77        DefaultMutableTreeNode n2 = new DefaultMutableTreeNode("Duke");
78        n1.add(n2);
79        DefaultMutableTreeNode n3 = new DefaultMutableTreeNode("Bug");
80        n2.add(n3);
81        n3.add(new DefaultMutableTreeNode("Blah"));
82        n3.add(new DefaultMutableTreeNode("Blah"));
83        n3.add(new DefaultMutableTreeNode("Blah"));
84        DefaultMutableTreeNode n4 = new DefaultMutableTreeNode("Here");
85        n2.add(n4);
86
87        JTree tree = new JTree(new DefaultTreeModel(n1));
88        tree.putClientProperty("JTree.lineStyle", "Angled");
89        tree.expandPath(new TreePath(new Object[]{n1, n2, n3}));
90        setContentPane(tree);
91    }
92}
93