Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTabbedPane/TestBackgroundScrollPolicy.java
41149 views
1
/*
2
* Copyright (c) 2020, 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
import java.awt.*;
25
import java.util.ArrayList;
26
import java.util.concurrent.CountDownLatch;
27
import javax.swing.JFrame;
28
import javax.swing.JLabel;
29
import javax.swing.JTabbedPane;
30
import javax.swing.UIManager;
31
import javax.swing.SwingUtilities;
32
import javax.swing.UnsupportedLookAndFeelException;
33
34
/*
35
* @test
36
* @key headful
37
* @bug 8172269 8244557
38
* @summary Tests JTabbedPane background for SCROLL_TAB_LAYOUT
39
* @run main TestBackgroundScrollPolicy
40
*/
41
42
public class TestBackgroundScrollPolicy {
43
private static Robot ROBOT;
44
45
public static void main(String[] args) throws Exception {
46
ROBOT = new Robot();
47
ROBOT.setAutoWaitForIdle(true);
48
ROBOT.setAutoDelay(100);
49
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
50
System.out.println("Testing L&F: " + laf.getClassName());
51
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
52
try {
53
SwingUtilities.invokeAndWait(() -> createGUI());
54
ROBOT.waitForIdle();
55
ROBOT.delay(1000);
56
SwingUtilities.invokeAndWait(() -> test(laf));
57
ROBOT.delay(2000);
58
} finally {
59
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
60
}
61
ROBOT.delay(1000);
62
}
63
}
64
65
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
66
try {
67
UIManager.setLookAndFeel(laf.getClassName());
68
} catch (UnsupportedLookAndFeelException ignored) {
69
System.out.println("Unsupported L&F: " + laf.getClassName());
70
} catch (ClassNotFoundException | InstantiationException
71
| IllegalAccessException e) {
72
throw new RuntimeException(e);
73
}
74
}
75
76
private static void addOpaqueError(UIManager.LookAndFeelInfo laf, boolean opaque) {
77
throw new RuntimeException(laf.getClassName() + " background color wrong for opaque=" + opaque);
78
}
79
80
private static JFrame frame;
81
private static JTabbedPane pane;
82
83
public static void createGUI() {
84
pane = new JTabbedPane();
85
pane.setOpaque(true);
86
pane.setBackground(Color.RED);
87
for (int i = 0; i < 3; i++) {
88
pane.addTab("Tab " + i, new JLabel("Content area " + i));
89
}
90
pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
91
pane.repaint();
92
frame = new JFrame();
93
frame.getContentPane().setBackground(Color.BLUE);
94
frame.add(pane);
95
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
96
frame.setSize(400, 200);
97
frame.setLocationRelativeTo(null);
98
frame.setVisible(true);
99
frame.toFront();
100
}
101
102
public static void test(UIManager.LookAndFeelInfo laf) {
103
Point point = new Point(pane.getWidth() - 2, 2);
104
SwingUtilities.convertPointToScreen(point, pane);
105
Color actual = ROBOT.getPixelColor(point.x, point.y);
106
107
boolean opaque = pane.isOpaque();
108
Color expected = opaque
109
? pane.getBackground()
110
: frame.getContentPane().getBackground();
111
112
if (!expected.equals(actual)){
113
System.out.println("expected " + expected + " actual " + actual);
114
addOpaqueError(laf, opaque);
115
}
116
117
}
118
}
119
120
121