1/* 2 * Copyright (c) 2015, 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 8040328 28 @summary JSlider has wrong preferred size with Synth LAF 29 @author Semyon Sadetsky 30 */ 31 32import javax.swing.*; 33import javax.swing.plaf.synth.SynthLookAndFeel; 34import java.awt.*; 35import java.io.ByteArrayInputStream; 36 37public class bug8040328 { 38 private static String synthXml = "<synth>" + 39 " <style id=\"all\">" + 40 " <font name=\"Segoe UI\" size=\"12\"/>" + 41 " </style>" + 42 " <bind style=\"all\" type=\"REGION\" key=\".*\"/>" + 43 " <style id=\"slider\">" + 44 " <insets top=\"10\" left=\"5\" bottom=\"10\" right=\"5\"/>" + 45 " </style>" + 46 " <bind style=\"slider\" type=\"region\" key=\"Slider\"/>" + 47 "</synth>"; 48 49 public static void main(String[] args) throws Exception { 50 SynthLookAndFeel lookAndFeel = new SynthLookAndFeel(); 51 lookAndFeel.load(new ByteArrayInputStream(synthXml.getBytes("UTF8")), 52 bug8040328.class); 53 UIManager.setLookAndFeel(lookAndFeel); 54 SwingUtilities.invokeAndWait(new Runnable() { 55 public void run() { 56 final JFrame frame = new JFrame(); 57 try { 58 frame.setUndecorated(true); 59 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 60 frame.setVisible(true); 61 test(frame); 62 } finally { 63 frame.dispose(); 64 } 65 } 66 }); 67 System.out.println("ok"); 68 } 69 70 static void test(JFrame frame) { 71 JSlider hslider = new JSlider(JSlider.HORIZONTAL); 72 hslider.setBackground(Color.DARK_GRAY); 73 frame.getContentPane().add(hslider, BorderLayout.CENTER); 74 frame.getContentPane().setBackground(Color.CYAN); 75 frame.pack(); 76 Insets insets = hslider.getInsets(); 77 if (hslider.getWidth() != 200 + insets.left + insets.right) { 78 throw new RuntimeException( 79 "Horizontal slider width is wrong " + hslider.getWidth()); 80 } 81 if (hslider.getHeight() != hslider.getMinimumSize().height) { 82 throw new RuntimeException( 83 "Horizontal slider height is wrong " + hslider.getHeight()); 84 } 85 frame.getContentPane().remove(hslider); 86 87 JSlider vslider = new JSlider(JSlider.VERTICAL); 88 frame.getContentPane().add(vslider); 89 frame.pack(); 90 insets = vslider.getInsets(); 91 if (vslider.getWidth() != vslider.getMinimumSize().width) { 92 throw new RuntimeException( 93 "Verical slider width is wrong " + vslider.getWidth()); 94 } 95 if (vslider.getHeight() != 200 + insets.top + insets.bottom) { 96 throw new RuntimeException( 97 "Verical slider height is wrong " + vslider.getHeight()); 98 } 99 } 100} 101