Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTree/4314199/bug4314199.java
38853 views
/*1* Copyright (c) 2012, 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*/222324/*25* @test26* @bug 431419927* @summary Tests that JTree repaints correctly in a container with a JMenu28* @author Peter Zhelezniakov29* @run applet/manual=yesno bug4314199.html30*/3132import javax.swing.*;33import javax.swing.tree.*;3435public class bug4314199 extends JApplet {3637public void init() {3839try {40UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");41SwingUtilities.invokeAndWait(new Runnable() {4243public void run() {44createAndShowGUI();45}46});47} catch (final Exception e) {48SwingUtilities.invokeLater(new Runnable() {4950public void run() {51createAndShowMessage("Test fails because of exception: "52+ e.getMessage());53}54});55}5657}5859private void createAndShowMessage(String message) {60getContentPane().add(new JLabel(message));61}6263private void createAndShowGUI() {64JMenuBar mb = new JMenuBar();6566// needed to exactly align left edge of menu and angled line of tree67mb.add(Box.createHorizontalStrut(27));6869JMenu mn = new JMenu("Menu");70JMenuItem mi = new JMenuItem("MenuItem");71mn.add(mi);72mb.add(mn);73setJMenuBar(mb);7475DefaultMutableTreeNode n1 = new DefaultMutableTreeNode("Root");76DefaultMutableTreeNode n2 = new DefaultMutableTreeNode("Duke");77n1.add(n2);78DefaultMutableTreeNode n3 = new DefaultMutableTreeNode("Bug");79n2.add(n3);80n3.add(new DefaultMutableTreeNode("Blah"));81n3.add(new DefaultMutableTreeNode("Blah"));82n3.add(new DefaultMutableTreeNode("Blah"));83DefaultMutableTreeNode n4 = new DefaultMutableTreeNode("Here");84n2.add(n4);8586JTree tree = new JTree(new DefaultTreeModel(n1));87tree.putClientProperty("JTree.lineStyle", "Angled");88tree.expandPath(new TreePath(new Object[]{n1, n2, n3}));89setContentPane(tree);90}91}929394