Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JToggleButton/4128979/bug4128979.java
41153 views
1
/*
2
* Copyright (c) 1998, 2021, 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 4128979
26
@requires (os.family == "windows")
27
@summary Tests that background changes correctly in WinLF for JToggleButton when pressed
28
@key headful
29
@run applet/manual=yesno bug4128979.html
30
*/
31
32
import javax.swing.BorderFactory;
33
import javax.swing.BoxLayout;
34
import javax.swing.Icon;
35
import javax.swing.JApplet;
36
import javax.swing.JFrame;
37
import javax.swing.JLabel;
38
import javax.swing.JOptionPane;
39
import javax.swing.JPanel;
40
import javax.swing.JToggleButton;
41
import javax.swing.JToolBar;
42
import javax.swing.UIManager;
43
import javax.swing.UnsupportedLookAndFeelException;
44
import javax.swing.WindowConstants;
45
import java.awt.BorderLayout;
46
import java.awt.Color;
47
import java.awt.Component;
48
import java.awt.ComponentOrientation;
49
import java.awt.Container;
50
import java.awt.FlowLayout;
51
import java.awt.Graphics;
52
53
public class bug4128979 extends JApplet {
54
55
public static void main(String[] args) {
56
JApplet applet = new bug4128979();
57
applet.init();
58
applet.start();
59
60
JFrame frame = new JFrame("Test window");
61
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
62
frame.setLayout(new BorderLayout());
63
frame.add(applet, BorderLayout.CENTER);
64
frame.setSize(600, 240);
65
frame.setVisible(true);
66
}
67
68
public void init() {
69
try {
70
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
71
} catch (UnsupportedLookAndFeelException e) {
72
JOptionPane.showMessageDialog(this,
73
"This test requires Windows look and feel, so just press Pass\n as "+
74
" this look and feel is unsupported on this platform.",
75
"Unsupported LF", JOptionPane.ERROR_MESSAGE);
76
return;
77
} catch (Exception e) {
78
throw new RuntimeException("Couldn't set look and feel");
79
}
80
81
setLayout(new FlowLayout());
82
JPanel p = new JPanel();
83
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
84
85
JPanel p1 = new JPanel();
86
addButtons(p1);
87
p.add(p1);
88
89
JToolBar tb1 = new JToolBar();
90
addButtons(tb1);
91
p.add(tb1);
92
93
JToolBar tb2 = new JToolBar();
94
tb2.setRollover(true);
95
addButtons(tb2);
96
p.add(tb2);
97
98
JLabel label = new JLabel("ToggleButton.highlight color: ");
99
label.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT);
100
label.setIcon(new Icon() {
101
public void paintIcon(Component c, Graphics g, int x, int y) {
102
g.setColor(UIManager.getColor("ToggleButton.highlight"));
103
g.fillRect(x, y, 49, 49);
104
g.setColor(new Color(~UIManager.getColor("ToggleButton.highlight").getRGB()));
105
g.drawRect(x, y, 49, 49);
106
}
107
108
public int getIconWidth() {
109
return 50;
110
}
111
112
public int getIconHeight() {
113
return 50;
114
}
115
});
116
add(p);
117
add(label);
118
}
119
120
static void addButtons(Container c) {
121
c.setLayout(new FlowLayout());
122
123
c.add(new JToggleButton("DefaultBorder"));
124
125
JToggleButton cbut = new JToggleButton("DefaultBorder");
126
cbut.setBackground(Color.red);
127
c.add(cbut);
128
cbut = new JToggleButton("DefaultBorder");
129
cbut.setBackground(Color.green);
130
c.add(cbut);
131
cbut = new JToggleButton("DefaultBorder");
132
cbut.setBackground(Color.blue);
133
c.add(cbut);
134
135
JToggleButton but3 = new JToggleButton("LineBorder");
136
but3.setBorder(BorderFactory.createLineBorder(Color.red));
137
c.add(but3);
138
139
JToggleButton but4 = new JToggleButton("null border");
140
but4.setBorder(null);
141
c.add(but4);
142
}
143
}
144
145