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