Skip to content

Commit f1343d0

Browse files
Abhishek Kumarpull[bot]
Abhishek Kumar
authored andcommitted
8327980: Convert javax/swing/JToggleButton/4128979/bug4128979.java applet test to main
Reviewed-by: honkar, tr
1 parent 50ca88c commit f1343d0

File tree

2 files changed

+51
-86
lines changed

2 files changed

+51
-86
lines changed

test/jdk/javax/swing/JToggleButton/4128979/bug4128979.html

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/jdk/javax/swing/JToggleButton/4128979/bug4128979.java renamed to test/jdk/javax/swing/JToggleButton/bug4128979.java

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,64 +21,67 @@
2121
* questions.
2222
*/
2323

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-
*/
24+
import java.awt.Color;
25+
import java.awt.Component;
26+
import java.awt.ComponentOrientation;
27+
import java.awt.Container;
28+
import java.awt.FlowLayout;
29+
import java.awt.Graphics;
3130

3231
import javax.swing.BorderFactory;
3332
import javax.swing.BoxLayout;
3433
import javax.swing.Icon;
35-
import javax.swing.JApplet;
3634
import javax.swing.JFrame;
3735
import javax.swing.JLabel;
38-
import javax.swing.JOptionPane;
3936
import javax.swing.JPanel;
4037
import javax.swing.JToggleButton;
4138
import javax.swing.JToolBar;
4239
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;
5240

53-
public class bug4128979 extends JApplet {
41+
import jtreg.SkippedException;
42+
import sun.awt.OSInfo;
5443

55-
public static void main(String[] args) {
56-
JApplet applet = new bug4128979();
57-
applet.init();
58-
applet.start();
44+
/* @test
45+
* @bug 4128979
46+
* @requires (os.family == "windows")
47+
* @modules java.desktop/sun.awt
48+
* @library /java/awt/regtesthelpers /test/lib
49+
* @build PassFailJFrame jtreg.SkippedException
50+
* @summary Tests that background changes correctly in WinLF for JToggleButton when pressed
51+
* @run main/manual bug4128979
52+
*/
5953

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-
}
54+
public class bug4128979 {
55+
private static final String INSTRUCTIONS = """
56+
When the test starts, toggle buttons are visible in three rows
57+
two of which are toolbars.
6758
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");
59+
Press these buttons, their background color must change
60+
to half tones between the button background colors and the ToggleButton
61+
highlight color (it is shown in the square below).
62+
63+
If the background color does not change correctly for at least one button,
64+
the test fails.""";
65+
66+
public static void main(String[] args) throws Exception {
67+
if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
68+
throw new SkippedException("This test is for Windows only");
7969
}
70+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
71+
PassFailJFrame.builder()
72+
.title("JToggleButton Instructions")
73+
.instructions(INSTRUCTIONS)
74+
.rows(15)
75+
.columns(60)
76+
.testUI(bug4128979::createAndShowUI)
77+
.build()
78+
.awaitAndCheck();
79+
}
80+
81+
public static JFrame createAndShowUI() {
82+
JFrame frame = new JFrame("JToggleButton's Background Color Test");
83+
frame.setLayout(new FlowLayout());
8084

81-
setLayout(new FlowLayout());
8285
JPanel p = new JPanel();
8386
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
8487

@@ -113,8 +116,11 @@ public int getIconHeight() {
113116
return 50;
114117
}
115118
});
116-
add(p);
117-
add(label);
119+
120+
frame.getContentPane().add(p);
121+
frame.getContentPane().add(label);
122+
frame.setSize(600, 250);
123+
return frame;
118124
}
119125

120126
static void addButtons(Container c) {

0 commit comments

Comments
 (0)