1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
* Copyright (c) 2007, 2025, 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 4230355
* @summary
* This test checks if progress bars lay out correctly when their
* ComponentOrientation property is set to RIGHT_TO_LEFT. This test is
* manual. The tester is asked to compare left-to-right and
* right-to-left progress bars and judge whether they are mirror images
* of each other.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual RightLeftOrientation
*/
import java.awt.ComponentOrientation;
import java.awt.Container;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.LookAndFeel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.UIManager;
public class RightLeftOrientation {
static final String INSTRUCTIONS = """
This test checks progress bars for correct Right-To-Left Component Orientation.
The progress bars in the left column should fill up from the left while the bars in
the right column should fill up from the right.
If this is so, the test PASSES, otherwise it FAILS.
""";
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("Progress Bar Orientation Test Instructions")
.instructions(INSTRUCTIONS)
.columns(60)
.testUI(RightLeftOrientation::createUI)
.build()
.awaitAndCheck();
}
static JFrame createUI() {
JFrame frame = new JFrame("Progress Bar Orientation Test");
Container contentPane = frame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
contentPane.add(createBarSet(ComponentOrientation.LEFT_TO_RIGHT));
contentPane.add(createBarSet(ComponentOrientation.RIGHT_TO_LEFT));
frame.pack();
return frame;
}
static JPanel createBarSet(ComponentOrientation o) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JLabel header;
if (o.isLeftToRight())
header = new JLabel("Left To Right");
else
header = new JLabel("Right To Left");
panel.add(header);
UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
for (int i = 0; i < lafs.length; i++) {
if (i > 0)
panel.add(Box.createVerticalStrut(10));
panel.add(createProgressBars(lafs[i].getName(),
lafs[i].getClassName(), o));
}
return panel;
}
static JPanel createProgressBars(String name, String plaf,
ComponentOrientation o) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JLabel label = new JLabel(name);
panel.add(label);
try {
LookAndFeel save = UIManager.getLookAndFeel();
UIManager.setLookAndFeel(plaf);
panel.add(createProgressBar(true, 0, o));
panel.add(Box.createVerticalStrut(5));
panel.add(createProgressBar(true, 5, o));
panel.add(Box.createVerticalStrut(5));
panel.add(createProgressBar(true, 10, o));
panel.add(Box.createVerticalStrut(5));
panel.add(createProgressBar(true, 20, o));
panel.add(Box.createVerticalStrut(5));
UIManager.put("ProgressBar.cellSpacing", Integer.valueOf(2));
UIManager.put("ProgressBar.cellLength", Integer.valueOf(7));
panel.add(createProgressBar(false, 5, o));
panel.add(Box.createVerticalStrut(5));
panel.add(createProgressBar(false, 20, o));
UIManager.setLookAndFeel(save);
} catch (Exception e) {
System.err.println(e);
}
return panel;
}
static JProgressBar createProgressBar(boolean paintStr, int value,
ComponentOrientation o) {
JProgressBar p = new JProgressBar(JProgressBar.HORIZONTAL, 0, 20);
p.setStringPainted(paintStr);
p.setValue(value);
p.setComponentOrientation(o);
return p;
}
}
|