|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 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 | + * @test |
| 26 | + * @bug 8041705 |
| 27 | + * @summary Bugs in DefaultTreeCellRenderer.updateUI() |
| 28 | + * @key headful |
| 29 | + * @run main DefaultTreeCellRendererBorderTest |
| 30 | + */ |
| 31 | + |
| 32 | +import java.awt.BorderLayout; |
| 33 | +import java.awt.Insets; |
| 34 | +import java.awt.Robot; |
| 35 | +import javax.swing.JFrame; |
| 36 | +import javax.swing.JTree; |
| 37 | +import javax.swing.SwingUtilities; |
| 38 | +import javax.swing.UIManager; |
| 39 | +import javax.swing.WindowConstants; |
| 40 | +import javax.swing.tree.DefaultTreeCellRenderer; |
| 41 | + |
| 42 | +public class DefaultTreeCellRendererBorderTest { |
| 43 | + private static JFrame frame; |
| 44 | + private static JTree tree; |
| 45 | + private static DefaultTreeCellRenderer treeCellRenderer; |
| 46 | + private static Robot robot; |
| 47 | + private static Insets margin1; |
| 48 | + private static Insets margin2; |
| 49 | + |
| 50 | + public static void main(String[] args) throws Exception { |
| 51 | + try{ |
| 52 | + robot = new Robot(); |
| 53 | + robot.setAutoDelay(50); |
| 54 | + SwingUtilities.invokeAndWait(()-> { |
| 55 | + frame = new JFrame(); |
| 56 | + tree = new JTree(); |
| 57 | + treeCellRenderer = new DefaultTreeCellRenderer(); |
| 58 | + tree.add(treeCellRenderer); |
| 59 | + frame.setDefaultCloseOperation( |
| 60 | + WindowConstants.DISPOSE_ON_CLOSE); |
| 61 | + frame.setSize(300,300); |
| 62 | + frame.setVisible(true); |
| 63 | + frame.setLayout(new BorderLayout()); |
| 64 | + tree.setRootVisible(true); |
| 65 | + tree.setShowsRootHandles(true); |
| 66 | + frame.add(tree, BorderLayout.CENTER); |
| 67 | + }); |
| 68 | + robot.waitForIdle(); |
| 69 | + |
| 70 | + UIManager.setLookAndFeel( |
| 71 | + "javax.swing.plaf.nimbus.NimbusLookAndFeel"); |
| 72 | + UIManager.put("Tree.rendererMargins", new Insets(2, 2, 2, 2)); |
| 73 | + SwingUtilities.invokeAndWait(() -> { |
| 74 | + SwingUtilities.updateComponentTreeUI(frame); |
| 75 | + margin1 = treeCellRenderer.getInsets(); |
| 76 | + }); |
| 77 | + robot.waitForIdle(); |
| 78 | + |
| 79 | + UIManager.put("Tree.rendererMargins", null); |
| 80 | + UIManager.setLookAndFeel( |
| 81 | + "javax.swing.plaf.metal.MetalLookAndFeel"); |
| 82 | + SwingUtilities.invokeAndWait(()->{ |
| 83 | + SwingUtilities.updateComponentTreeUI(frame); |
| 84 | + margin2 = treeCellRenderer.getInsets(); |
| 85 | + }); |
| 86 | + robot.waitForIdle(); |
| 87 | + |
| 88 | + if(margin1.equals(margin2)) { |
| 89 | + throw new RuntimeException("Test Failed : NimbusLookAndFeel "+ |
| 90 | + "Border persists for MetalLookAndFeel"); |
| 91 | + } |
| 92 | + } finally { |
| 93 | + if(frame != null) { |
| 94 | + SwingUtilities.invokeAndWait(frame::dispose); |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments