Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JSlider/6587742/bug6587742.java
41153 views
1
/*
2
* Copyright (c) 2008, 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 6587742
26
* @summary filling half of a JSlider's track is no longer optional
27
* @author Pavel Porvatov
28
* @run applet/manual=done bug6587742.html
29
*/
30
31
import javax.swing.*;
32
import javax.swing.plaf.metal.DefaultMetalTheme;
33
import javax.swing.plaf.metal.MetalLookAndFeel;
34
import javax.swing.plaf.metal.MetalTheme;
35
import javax.swing.plaf.metal.OceanTheme;
36
import java.awt.event.ItemEvent;
37
import java.awt.event.ItemListener;
38
39
public class bug6587742 extends JApplet {
40
public void init() {
41
TestPanel panel = new TestPanel();
42
43
setContentPane(panel);
44
}
45
46
private class TestPanel extends JPanel {
47
private final JComboBox cbThemes = new JComboBox();
48
49
private TestPanel() {
50
// Fill cbThemes
51
cbThemes.addItem(new OceanTheme());
52
cbThemes.addItem(new DefaultMetalTheme());
53
54
cbThemes.addItemListener(new ItemListener() {
55
public void itemStateChanged(ItemEvent e) {
56
MetalTheme theme = (MetalTheme) cbThemes.getSelectedItem();
57
58
if (theme != null) {
59
MetalLookAndFeel.setCurrentTheme(theme);
60
61
// re-install the Metal Look and Feel
62
try {
63
UIManager.setLookAndFeel(new MetalLookAndFeel());
64
} catch (UnsupportedLookAndFeelException e1) {
65
JOptionPane.showMessageDialog(TestPanel.this, "Can't change theme: " + e1.getMessage(),
66
"Error", JOptionPane.ERROR_MESSAGE);
67
68
return;
69
}
70
71
SwingUtilities.updateComponentTreeUI(bug6587742.this);
72
}
73
}
74
});
75
76
JPanel pnVertical = new JPanel();
77
78
pnVertical.setLayout(new BoxLayout(pnVertical, BoxLayout.Y_AXIS));
79
80
for (int i = 0; i < 12; i++) {
81
int filled = i >> 2;
82
83
pnVertical.add(createSlider(false, filled > 1 ? null : Boolean.valueOf(filled == 1), (i & 2) == 0,
84
(i & 1) != 0));
85
}
86
87
JPanel pnHorizontal = new JPanel();
88
89
pnHorizontal.setLayout(new BoxLayout(pnHorizontal, BoxLayout.X_AXIS));
90
91
for (int i = 0; i < 12; i++) {
92
int filled = i >> 2;
93
94
pnHorizontal.add(createSlider(true, filled > 1 ? null : Boolean.valueOf(filled == 1), (i & 2) == 0,
95
(i & 1) != 0));
96
}
97
98
JTabbedPane tpSliders = new JTabbedPane();
99
100
tpSliders.add("Vertical sliders", pnVertical);
101
tpSliders.add("Horizontal sliders", pnHorizontal);
102
103
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
104
105
add(new JLabel("Select theme:"));
106
add(cbThemes);
107
add(tpSliders);
108
}
109
}
110
111
private static JSlider createSlider(boolean vertical, Boolean filled, boolean enabled, boolean inverted) {
112
JSlider result = new JSlider(vertical ? SwingConstants.VERTICAL : SwingConstants.HORIZONTAL, 0, 100, 50);
113
114
result.setMajorTickSpacing(20);
115
result.setMinorTickSpacing(5);
116
result.setPaintTicks(true);
117
result.setPaintLabels(true);
118
result.setEnabled(enabled);
119
120
if (filled != null) {
121
result.putClientProperty("JSlider.isFilled", filled);
122
}
123
124
result.setInverted(inverted);
125
result.setToolTipText("<html>vertical = " + vertical + "<br>enabled = " + enabled + "<br>filled = " + filled +
126
"<br>inverted = " + inverted + "</html>");
127
128
return result;
129
}
130
}
131
132