|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 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 8318577 |
| 27 | + * @summary Tests JProgressBarUI renders correctly in Windows L&F |
| 28 | + * @requires (os.family == "windows") |
| 29 | + * @library /java/awt/regtesthelpers |
| 30 | + * @build PassFailJFrame |
| 31 | + * @run main/manual TestProgressBarUI |
| 32 | + */ |
| 33 | + |
| 34 | +import java.awt.BorderLayout; |
| 35 | +import java.awt.Color; |
| 36 | +import java.awt.Dimension; |
| 37 | +import java.awt.FlowLayout; |
| 38 | + |
| 39 | +import javax.swing.JComponent; |
| 40 | +import javax.swing.JFrame; |
| 41 | +import javax.swing.JPanel; |
| 42 | +import javax.swing.JProgressBar; |
| 43 | +import javax.swing.SwingUtilities; |
| 44 | +import javax.swing.UIManager; |
| 45 | + |
| 46 | +public class TestProgressBarUI { |
| 47 | + |
| 48 | + private static final String instructionsText = """ |
| 49 | + Two progressbar "Good" and "Bad" |
| 50 | + will be shown with different preferred size, |
| 51 | + If the "Bad" progressbar is rendered at the same |
| 52 | + height as "Good" progressbar, |
| 53 | + without any difference in padding internally |
| 54 | + the test passes, otherwise fails. """; |
| 55 | + |
| 56 | + public static void main(String[] args) throws Exception { |
| 57 | + System.setProperty("sun.java2d.uiScale", "2.0"); |
| 58 | + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 59 | + PassFailJFrame.builder() |
| 60 | + .title("ProgressBar Instructions") |
| 61 | + .instructions(instructionsText) |
| 62 | + .rows(9) |
| 63 | + .columns(36) |
| 64 | + .testUI(TestProgressBarUI::doTest) |
| 65 | + .build() |
| 66 | + .awaitAndCheck(); |
| 67 | + } |
| 68 | + |
| 69 | + public static JFrame doTest() { |
| 70 | + JFrame frame = new JFrame("JProgressBar"); |
| 71 | + |
| 72 | + JPanel panel = new JPanel(new FlowLayout(20, 20, FlowLayout.LEADING)); |
| 73 | + panel.setBackground(Color.white); |
| 74 | + |
| 75 | + JProgressBar p1 = new JProgressBar(0, 100); |
| 76 | + p1.setValue(50); |
| 77 | + p1.setStringPainted(true); |
| 78 | + p1.setString("GOOD"); |
| 79 | + p1.setPreferredSize(new Dimension(100, 21)); |
| 80 | + panel.add(p1); |
| 81 | + |
| 82 | + JProgressBar p2 = new JProgressBar(0, 100); |
| 83 | + p2.setValue(50); |
| 84 | + p2.setStringPainted(true); |
| 85 | + p2.setString("BAD"); |
| 86 | + |
| 87 | + p2.setPreferredSize(new Dimension(100, 22)); |
| 88 | + panel.add(p2); |
| 89 | + |
| 90 | + JComponent c = (JComponent) frame.getContentPane(); |
| 91 | + c.add(panel, BorderLayout.CENTER); |
| 92 | + |
| 93 | + frame.pack(); |
| 94 | + frame.setLocationByPlatform(true); |
| 95 | + return frame; |
| 96 | + } |
| 97 | +} |
0 commit comments