Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JMenu/8178430/LabelDotTest.java
41153 views
1
/*
2
* Copyright (c) 2009, 2017, 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 8178430
27
* @summary JMenu in GridBagLayout flickers when label text shows "..." and
28
* is updated
29
* @key headful
30
* @run main LabelDotTest
31
*/
32
33
import java.awt.Dimension;
34
import java.awt.GridBagConstraints;
35
import java.awt.GridBagLayout;
36
import java.awt.Robot;
37
38
import java.util.stream.IntStream;
39
40
import javax.swing.SwingUtilities;
41
import javax.swing.JLabel;
42
import javax.swing.JMenu;
43
import javax.swing.JFrame;
44
import javax.swing.JMenuBar;
45
import javax.swing.JPanel;
46
import javax.swing.SwingConstants;
47
48
public class LabelDotTest
49
{
50
private final static String longText = "show a very long text to have it " +
51
"automatically shortened";
52
private final static String shortText = "show short text";
53
54
private static JFrame frame;
55
private static JLabel label;
56
private static JMenu menu;
57
private static volatile boolean isException = false;
58
59
private static void createUI() {
60
System.out.println("BEFORE CREATION");
61
frame = new JFrame();
62
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
63
frame.setSize(new Dimension(50, 150));
64
frame.setLocationRelativeTo(null);
65
66
frame.setLayout(new GridBagLayout());
67
GridBagConstraints c = new GridBagConstraints();
68
c.fill = GridBagConstraints.BOTH;
69
c.weightx = 1.0;
70
c.weighty = 0.0;
71
c.gridwidth = GridBagConstraints.REMAINDER;
72
73
JMenuBar menuBar = new JMenuBar();
74
menu = new JMenu("Menu");
75
menuBar.add(menu);
76
frame.add(menuBar, c);
77
78
frame.add(new JLabel("Title", SwingConstants.CENTER), c);
79
80
c.weighty = 1.0;
81
frame.add(new JPanel(new GridBagLayout()), c);
82
c.weighty = 0.0;
83
84
label = new JLabel(shortText);
85
frame.add(label, c);
86
87
frame.setVisible(true);
88
}
89
90
private static void runTest(int iterations) throws Exception{
91
Robot robot = new Robot();
92
93
IntStream.range(0, iterations).forEach((i) -> {
94
SwingUtilities.invokeLater(() -> {
95
if (label.getText().equals(shortText)) {
96
label.setText(longText);
97
} else {
98
label.setText(shortText);
99
}
100
/* For a top level menu item, minimum size and the
101
preferred size should be the same, and should not be
102
equal to 1. Save the exception state and throw later
103
once the iterations are completed.
104
*/
105
isException = (menu.getMinimumSize().height == 1 &&
106
!menu.getMinimumSize().equals(menu.getPreferredSize())) ||
107
isException;
108
});
109
robot.waitForIdle();
110
});
111
}
112
113
public static void main(String[] args) throws Exception {
114
try {
115
SwingUtilities.invokeAndWait(() -> createUI());
116
runTest(50);
117
} finally {
118
if (frame != null) {
119
SwingUtilities.invokeAndWait(() -> frame.dispose());
120
}
121
if (isException)
122
throw new RuntimeException("Size of Menu bar is not correct.");
123
}
124
}
125
}
126
127