Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComboBox/7195179/Test7195179.java
41153 views
1
/*
2
* Copyright (c) 2013, 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.Component;
25
import javax.swing.GroupLayout;
26
import javax.swing.JComboBox;
27
import javax.swing.JFrame;
28
import javax.swing.JLabel;
29
import javax.swing.JList;
30
import javax.swing.JPanel;
31
import javax.swing.ListCellRenderer;
32
import javax.swing.plaf.basic.BasicComboBoxRenderer;
33
34
import static javax.swing.SwingUtilities.invokeAndWait;
35
36
/*
37
* @test
38
* @key headful
39
* @bug 7195179
40
* @summary Tests that combobox works with generified renderers
41
* @author Sergey Malenkov
42
*/
43
44
public class Test7195179 {
45
private static JFrame frame;
46
public static void main(String[] args) throws Exception {
47
invokeAndWait(new Runnable() {
48
@Override
49
public void run() {
50
try {
51
Integer[] items = {null, 1, 2, 3};
52
JComboBox<Integer> combo = new JComboBox<>(items);
53
JLabel label = new JLabel("choose:");
54
JPanel panel = new JPanel();
55
GroupLayout layout = new GroupLayout(panel);
56
panel.setLayout(layout);
57
label.setLabelFor(combo);
58
combo.setSelectedIndex(0);
59
combo.setRenderer(new ListCellRenderer<Integer>() {
60
private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer();
61
62
@Override
63
public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) {
64
return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
65
}
66
});
67
layout.setAutoCreateContainerGaps(true);
68
layout.setAutoCreateGaps(true);
69
layout.setHorizontalGroup(layout.createSequentialGroup()
70
.addGroup(layout.createParallelGroup().addComponent(label))
71
.addGroup(layout.createParallelGroup().addComponent(combo)));
72
layout.setVerticalGroup(layout
73
.createSequentialGroup()
74
.addGroup(layout
75
.createParallelGroup(GroupLayout.Alignment.BASELINE)
76
.addComponent(label)
77
.addComponent(combo)));
78
79
frame = new JFrame(getClass().getSimpleName());
80
frame.add(panel);
81
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
82
frame.pack();
83
frame.setVisible(true);
84
} finally {
85
if (frame != null) frame.dispose();
86
}
87
}
88
});
89
}
90
}
91
92