From 72f3a466e0eab223530607d73d06749d5fb7ad40 Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Tue, 17 Mar 2015 14:38:22 +0400 Subject: [PATCH] 8040328: JSlider has wrong preferred size with Synth LAF Reviewed-by: alexsch, ant --- .../javax/swing/plaf/synth/SynthSliderUI.java | 6 +- .../swing/plaf/synth/8040328/bug8040328.java | 98 +++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 jdk/test/javax/swing/plaf/synth/8040328/bug8040328.java diff --git a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java index 2116e65a0f4..912f3f43e7f 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthSliderUI.java @@ -308,14 +308,14 @@ public class SynthSliderUI extends BasicSliderUI public Dimension getPreferredSize(JComponent c) { recalculateIfInsetsChanged(); Dimension d = new Dimension(contentRect.width, contentRect.height); + Insets i = slider.getInsets(); if (slider.getOrientation() == JSlider.VERTICAL) { d.height = 200; + d.height += i.top + i.bottom; } else { d.width = 200; + d.width += i.left + i.right; } - Insets i = slider.getInsets(); - d.width += i.left + i.right; - d.height += i.top + i.bottom; return d; } diff --git a/jdk/test/javax/swing/plaf/synth/8040328/bug8040328.java b/jdk/test/javax/swing/plaf/synth/8040328/bug8040328.java new file mode 100644 index 00000000000..72a0e46885f --- /dev/null +++ b/jdk/test/javax/swing/plaf/synth/8040328/bug8040328.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + @bug 8040328 + @summary JSlider has wrong preferred size with Synth LAF + @author Semyon Sadetsky +*/ + +import javax.swing.*; +import javax.swing.plaf.synth.SynthLookAndFeel; +import java.awt.*; +import java.io.ByteArrayInputStream; + +public class bug8040328 { + private static String synthXml = "" + + " " + + " " + + " " + + " " + + ""; + + public static void main(String[] args) throws Exception { + SynthLookAndFeel lookAndFeel = new SynthLookAndFeel(); + lookAndFeel.load(new ByteArrayInputStream(synthXml.getBytes("UTF8")), + bug8040328.class); + UIManager.setLookAndFeel(lookAndFeel); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + final JFrame frame = new JFrame(); + try { + frame.setUndecorated(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + test(frame); + } finally { + frame.dispose(); + } + } + }); + System.out.println("ok"); + } + + static void test(JFrame frame) { + JSlider hslider = new JSlider(JSlider.HORIZONTAL); + hslider.setBackground(Color.DARK_GRAY); + frame.getContentPane().add(hslider, BorderLayout.CENTER); + frame.getContentPane().setBackground(Color.CYAN); + frame.pack(); + Insets insets = hslider.getInsets(); + if (hslider.getWidth() != 200 + insets.left + insets.right) { + throw new RuntimeException( + "Horizontal slider width is wrong " + hslider.getWidth()); + } + if (hslider.getHeight() != hslider.getMinimumSize().height) { + throw new RuntimeException( + "Horizontal slider height is wrong " + hslider.getHeight()); + } + frame.getContentPane().remove(hslider); + + JSlider vslider = new JSlider(JSlider.VERTICAL); + frame.getContentPane().add(vslider); + frame.pack(); + insets = vslider.getInsets(); + if (vslider.getWidth() != vslider.getMinimumSize().width) { + throw new RuntimeException( + "Verical slider width is wrong " + vslider.getWidth()); + } + if (vslider.getHeight() != 200 + insets.top + insets.bottom) { + throw new RuntimeException( + "Verical slider height is wrong " + vslider.getHeight()); + } + } +}