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