Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTabbedPane/TabProb.java
41149 views
1
/*
2
* Copyright (c) 2019, 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
/* @test
25
@bug 8215396
26
@key headful
27
@summary Verifies JTabbedPane preferred size calculation is wrong
28
for SCROLL_TAB_LAYOUT.
29
@run main TabProb
30
*/
31
32
import java.awt.Component;
33
import java.awt.Container;
34
import java.awt.Color;
35
import java.awt.BorderLayout;
36
import java.awt.Dimension;
37
import java.awt.LayoutManager;
38
import java.awt.Insets;
39
import java.awt.Robot;
40
import javax.swing.BorderFactory;
41
import javax.swing.JFrame;
42
import javax.swing.JLabel;
43
import javax.swing.JPanel;
44
import javax.swing.JTabbedPane;
45
import javax.swing.SwingUtilities;
46
import javax.swing.UIManager;
47
48
public class TabProb extends JFrame {
49
static TabProb tb1;
50
static TabProb tb2;
51
class FixLayout implements LayoutManager {
52
@Override
53
public void layoutContainer(Container C) {
54
Insets in = C.getInsets();
55
int w = 200 - in.left - in.right;
56
int h = 100 - in.top - in.bottom;
57
C.getComponents()[0].setBounds(in.top, in.left, w, h);
58
}
59
@Override
60
public Dimension minimumLayoutSize(Container C) {
61
return new Dimension(200, 100);
62
}
63
@Override
64
public Dimension preferredLayoutSize(Container C) {
65
return new Dimension(200, 100);
66
}
67
@Override
68
public void removeLayoutComponent(Component c) {
69
}
70
@Override
71
public void addLayoutComponent(String s, Component c) {
72
}
73
}
74
75
public TabProb(int layoutPolicy) {
76
JTabbedPane tabpanel = new JTabbedPane();
77
tabpanel.setTabPlacement(JTabbedPane.TOP);
78
tabpanel.setTabLayoutPolicy(layoutPolicy);
79
JPanel panel = new JPanel(new FixLayout());
80
JLabel label = new JLabel("Label");
81
label.setBorder(BorderFactory.createLineBorder(Color.green, 3));
82
panel.add(label);
83
tabpanel.add("TEST", panel);
84
add(tabpanel, BorderLayout.CENTER);
85
setUndecorated(true);
86
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
87
}
88
89
public static void main(String[] args) throws Exception {
90
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
91
System.out.println("Test for LookAndFeel " + laf.getClassName());
92
UIManager.setLookAndFeel(laf.getClassName());
93
test();
94
System.out.println("Test passed for LookAndFeel " + laf.getClassName());
95
}
96
}
97
98
public static void test() throws Exception {
99
Robot robot = new Robot();
100
SwingUtilities.invokeAndWait(new Runnable() {
101
@Override
102
public void run() {
103
tb1 = new TabProb(JTabbedPane.SCROLL_TAB_LAYOUT);
104
tb1.pack();
105
tb1.setVisible(true);
106
107
tb2 = new TabProb(JTabbedPane.WRAP_TAB_LAYOUT);
108
tb2.pack();
109
tb2.setVisible(true);
110
}
111
});
112
double tb1height = tb1.getPreferredSize().getHeight();
113
double tb2height = tb2.getPreferredSize().getHeight();
114
System.out.println(tb1height);
115
System.out.println(tb2height);
116
117
robot.waitForIdle();
118
robot.delay(2000);
119
120
SwingUtilities.invokeAndWait(() -> tb1.dispose());
121
SwingUtilities.invokeAndWait(() -> tb2.dispose());
122
123
if (tb1height != tb2height) {
124
throw new RuntimeException("JTabbedPane preferred size calculation is wrong for SCROLL_TAB_LAYOUT");
125
}
126
}
127
}
128
129