Path: blob/master/test/jdk/javax/swing/JSplitPane/4885629/bug4885629.java
41153 views
/*1* Copyright (c) 2011, 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*/2223/*24* @test25* @key headful26* @bug 488562927* @summary With JSplitPane in VERTICAL_SPLIT, SplitPaneBorder draws bottom edge of divider28* @author Andrey Pikalev29*/3031import javax.swing.*;32import javax.swing.border.Border;33import javax.swing.border.EmptyBorder;34import javax.swing.plaf.basic.BasicBorders;35import javax.swing.plaf.basic.BasicLookAndFeel;36import javax.swing.plaf.basic.BasicSplitPaneUI;37import java.awt.*;383940public class bug4885629 {4142private static final Color darkShadow = new Color(100,120,200);43private static final Color darkHighlight = new Color(200,120,50);44private static final Color lightHighlight = darkHighlight.brighter();45private static final Color BGCOLOR = Color.blue;4647private static JSplitPane sp;48private static JFrame frame;4950public static void main(String[] args) throws Exception {51UIManager.setLookAndFeel(new BasicLookAndFeel() {52public boolean isSupportedLookAndFeel(){ return true; }53public boolean isNativeLookAndFeel(){ return false; }54public String getDescription() { return "Foo"; }55public String getID() { return "FooID"; }56public String getName() { return "FooName"; }57});5859try {60SwingUtilities.invokeAndWait(new Runnable() {61public void run() {62frame = new JFrame();6364JComponent a = new JPanel();65a.setBackground(Color.white);66a.setMinimumSize(new Dimension(10, 10));6768JComponent b = new JPanel();69b.setBackground(Color.white);70b.setMinimumSize(new Dimension(10, 10));7172sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, a, b);73sp.setPreferredSize(new Dimension(20, 20));74sp.setBackground(BGCOLOR);7576Border bo = new BasicBorders.SplitPaneBorder(lightHighlight,77Color.red);78Border ibo = new EmptyBorder(0, 0, 0, 0);79sp.setBorder(bo);80sp.setMinimumSize(new Dimension(200, 200));8182((BasicSplitPaneUI) sp.getUI()).getDivider().setBorder(ibo);8384frame.getContentPane().setLayout(new FlowLayout());85frame.getContentPane().setBackground(darkShadow);86frame.getContentPane().add(sp);8788frame.setSize(200, 200);89frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);90frame.setVisible(true);91}92});9394final Robot robot = new Robot();95robot.waitForIdle();96robot.delay(1000);9798SwingUtilities.invokeAndWait(new Runnable() {99public void run() {100Rectangle rect = ((BasicSplitPaneUI) sp.getUI()).getDivider().getBounds();101102Point p = rect.getLocation();103104SwingUtilities.convertPointToScreen(p, sp);105106for (int i = 0; i < rect.width; i++) {107if (!BGCOLOR.equals(robot.getPixelColor(p.x + i, p.y + rect.height - 1))) {108throw new Error("The divider's area has incorrect color.");109}110}111}112});113} finally {114if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());115}116}117}118119120