1 /* 2 * Copyright (c) 2011, 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 * @test 26 * @key headful 27 * @bug 4885629 28 * @summary With JSplitPane in VERTICAL_SPLIT, SplitPaneBorder draws bottom edge of divider 29 * @author Andrey Pikalev 30 */ 31 32 import sun.awt.SunToolkit; 33 34 import javax.swing.*; 35 import javax.swing.border.Border; 36 import javax.swing.border.EmptyBorder; 37 import javax.swing.plaf.basic.BasicBorders; 38 import javax.swing.plaf.basic.BasicLookAndFeel; 39 import javax.swing.plaf.basic.BasicSplitPaneUI; 40 import java.awt.*; 41 42 43 public class bug4885629 { 44 45 private static final Color darkShadow = new Color(100,120,200); 46 private static final Color darkHighlight = new Color(200,120,50); 47 private static final Color lightHighlight = darkHighlight.brighter(); 48 private static final Color BGCOLOR = Color.blue; 49 50 private static JSplitPane sp; 51 52 public static void main(String[] args) throws Exception { 53 UIManager.setLookAndFeel(new BasicLookAndFeel() { 54 public boolean isSupportedLookAndFeel(){ return true; } 55 public boolean isNativeLookAndFeel(){ return false; } 56 public String getDescription() { return "Foo"; } 57 public String getID() { return "FooID"; } 58 public String getName() { return "FooName"; } 59 }); 60 61 SwingUtilities.invokeAndWait(new Runnable() { 62 public void run() { 63 JFrame frame = new JFrame(); 64 65 JComponent a = new JPanel(); 66 a.setBackground(Color.white); 67 a.setMinimumSize(new Dimension(10, 10)); 68 69 JComponent b = new JPanel(); 70 b.setBackground(Color.white); 71 b.setMinimumSize(new Dimension(10, 10)); 72 73 sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, a, b); 74 sp.setPreferredSize(new Dimension(20, 20)); 75 sp.setBackground(BGCOLOR); 76 77 Border bo = new BasicBorders.SplitPaneBorder(lightHighlight, 78 Color.red); 79 Border ibo = new EmptyBorder(0, 0, 0, 0); 80 sp.setBorder(bo); 81 sp.setMinimumSize(new Dimension(200, 200)); 82 83 ((BasicSplitPaneUI) sp.getUI()).getDivider().setBorder(ibo); 84 85 frame.getContentPane().setLayout(new FlowLayout()); 86 frame.getContentPane().setBackground(darkShadow); 87 frame.getContentPane().add(sp); 88 89 frame.setSize(200, 200); 90 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 91 frame.setVisible(true); 92 } 93 }); 94 95 ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); 96 97 final Robot robot = new Robot(); 98 robot.delay(1000); 99 100 SwingUtilities.invokeAndWait(new Runnable() { 101 public void run() { 102 Rectangle rect = ((BasicSplitPaneUI) sp.getUI()).getDivider().getBounds(); 103 104 Point p = rect.getLocation(); 105 106 SwingUtilities.convertPointToScreen(p, sp); 107 108 for (int i = 0; i < rect.width; i++) { 109 if (!BGCOLOR.equals(robot.getPixelColor(p.x + i, p.y + rect.height - 1))) { 110 throw new Error("The divider's area has incorrect color."); 111 } 112 } 113 } 114 }); 115 } 116 }