|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
21 | 21 | * questions.
|
22 | 22 | */
|
23 | 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 |
| -*/ |
| 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; |
31 | 30 |
|
32 | 31 | import javax.swing.BorderFactory;
|
33 | 32 | import javax.swing.BoxLayout;
|
34 | 33 | import javax.swing.Icon;
|
35 |
| -import javax.swing.JApplet; |
36 | 34 | import javax.swing.JFrame;
|
37 | 35 | import javax.swing.JLabel;
|
38 |
| -import javax.swing.JOptionPane; |
39 | 36 | import javax.swing.JPanel;
|
40 | 37 | import javax.swing.JToggleButton;
|
41 | 38 | import javax.swing.JToolBar;
|
42 | 39 | 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 | 40 |
|
53 |
| -public class bug4128979 extends JApplet { |
| 41 | +import jtreg.SkippedException; |
| 42 | +import sun.awt.OSInfo; |
54 | 43 |
|
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 | + */ |
59 | 53 |
|
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. |
67 | 58 |
|
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"); |
79 | 69 | }
|
| 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()); |
80 | 84 |
|
81 |
| - setLayout(new FlowLayout()); |
82 | 85 | JPanel p = new JPanel();
|
83 | 86 | p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
|
84 | 87 |
|
@@ -113,8 +116,11 @@ public int getIconHeight() {
|
113 | 116 | return 50;
|
114 | 117 | }
|
115 | 118 | });
|
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; |
118 | 124 | }
|
119 | 125 |
|
120 | 126 | static void addButtons(Container c) {
|
|
0 commit comments