Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JSlider/4987336/bug4987336.java
41153 views
1
/*
2
* Copyright (c) 2007, 2018, 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 4987336
26
@summary JSlider doesn't show label's animated icon.
27
@author Pavel Porvatov
28
@run applet/manual=done bug4987336.html
29
*/
30
31
import javax.swing.*;
32
import javax.swing.border.TitledBorder;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35
import java.util.Hashtable;
36
37
public class bug4987336 extends JApplet {
38
private static final String IMAGE_RES = "box.gif";
39
40
private static final String ANIM_IMAGE_RES = "duke.gif";
41
42
public void init() {
43
JPanel pnLafs = new JPanel();
44
pnLafs.setLayout(new BoxLayout(pnLafs, BoxLayout.Y_AXIS));
45
46
ButtonGroup group = new ButtonGroup();
47
48
pnLafs.setBorder(new TitledBorder("Available Lafs"));
49
50
for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) {
51
LafRadioButton comp = new LafRadioButton(lafInfo);
52
53
pnLafs.add(comp);
54
group.add(comp);
55
}
56
57
JPanel pnContent = new JPanel();
58
59
pnContent.setLayout(new BoxLayout(pnContent, BoxLayout.Y_AXIS));
60
61
pnContent.add(pnLafs);
62
pnContent.add(createSlider(true, IMAGE_RES, IMAGE_RES, ANIM_IMAGE_RES, ANIM_IMAGE_RES));
63
pnContent.add(createSlider(false, IMAGE_RES, IMAGE_RES, ANIM_IMAGE_RES, ANIM_IMAGE_RES));
64
pnContent.add(createSlider(true, ANIM_IMAGE_RES, null, IMAGE_RES, IMAGE_RES));
65
pnContent.add(createSlider(false, ANIM_IMAGE_RES, null, IMAGE_RES, IMAGE_RES));
66
67
getContentPane().add(new JScrollPane(pnContent));
68
}
69
70
private static JSlider createSlider(boolean enabled,
71
String firstEnabledImage, String firstDisabledImage,
72
String secondEnabledImage, String secondDisabledImage) {
73
Hashtable<Integer, JComponent> dictionary = new Hashtable<Integer, JComponent>();
74
75
dictionary.put(0, createLabel(firstEnabledImage, firstDisabledImage));
76
dictionary.put(1, createLabel(secondEnabledImage, secondDisabledImage));
77
78
JSlider result = new JSlider(0, 1);
79
80
result.setLabelTable(dictionary);
81
result.setPaintLabels(true);
82
result.setEnabled(enabled);
83
84
return result;
85
}
86
87
private static JLabel createLabel(String enabledImage, String disabledImage) {
88
ImageIcon enabledIcon = enabledImage == null ? null :
89
new ImageIcon(bug4987336.class.getResource(enabledImage));
90
91
ImageIcon disabledIcon = disabledImage == null ? null :
92
new ImageIcon(bug4987336.class.getResource(disabledImage));
93
94
JLabel result = new JLabel(enabledImage == null && disabledImage == null ? "No image" : "Image",
95
enabledIcon, SwingConstants.LEFT);
96
97
result.setDisabledIcon(disabledIcon);
98
99
return result;
100
}
101
102
private class LafRadioButton extends JRadioButton {
103
public LafRadioButton(final UIManager.LookAndFeelInfo lafInfo) {
104
super(lafInfo.getName(), lafInfo.getName().equals(UIManager.getLookAndFeel().getName()));
105
106
addActionListener(new ActionListener() {
107
public void actionPerformed(ActionEvent e) {
108
try {
109
UIManager.setLookAndFeel(lafInfo.getClassName());
110
111
SwingUtilities.updateComponentTreeUI(bug4987336.this);
112
} catch (Exception ex) {
113
// Ignore such errors
114
System.out.println("Cannot set LAF " + lafInfo.getName());
115
}
116
}
117
});
118
}
119
}
120
}
121
122