|
1 | 1 | /* |
2 | | - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2008, 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 | +import java.awt.BorderLayout; |
| 25 | +import javax.swing.JCheckBox; |
| 26 | +import javax.swing.JColorChooser; |
| 27 | +import javax.swing.JFrame; |
| 28 | + |
24 | 29 | /* |
25 | 30 | * @test |
26 | 31 | * @bug 4222508 |
| 32 | + * @library /java/awt/regtesthelpers |
| 33 | + * @build PassFailJFrame |
27 | 34 | * @summary Tests the color chooser disabling |
28 | | - * @author Sergey Malenkov |
29 | | - * @run applet/manual=yesno Test4222508.html |
| 35 | + * @run main/manual Test4222508 |
30 | 36 | */ |
| 37 | +public final class Test4222508 { |
31 | 38 |
|
32 | | -import java.awt.BorderLayout; |
33 | | -import java.awt.event.ItemEvent; |
34 | | -import java.awt.event.ItemListener; |
35 | | -import javax.swing.JApplet; |
36 | | -import javax.swing.JCheckBox; |
37 | | -import javax.swing.JColorChooser; |
| 39 | + public static void main(String[] args) throws Exception { |
| 40 | + String instructions = "Click on colors in the JColorChooser.\n" + |
| 41 | + "Then uncheck the checkbox and click on colors again.\n" + |
| 42 | + "If the JColorChooser is disabled when the checkbox is unchecked, " + |
| 43 | + "then pass the test."; |
38 | 44 |
|
39 | | -public final class Test4222508 extends JApplet implements ItemListener { |
| 45 | + PassFailJFrame.builder() |
| 46 | + .title("Test4222508") |
| 47 | + .instructions(instructions) |
| 48 | + .rows(5) |
| 49 | + .columns(40) |
| 50 | + .testTimeOut(10) |
| 51 | + .testUI(Test4222508::test) |
| 52 | + .build() |
| 53 | + .awaitAndCheck(); |
| 54 | + } |
40 | 55 |
|
41 | | - private JCheckBox checkbox; |
42 | | - private JColorChooser chooser; |
| 56 | + public static JFrame test() { |
| 57 | + JFrame frame = new JFrame("JColorChooser with enable/disable checkbox"); |
| 58 | + frame.setLayout(new BorderLayout()); |
| 59 | + JColorChooser chooser = new JColorChooser(); |
| 60 | + JCheckBox checkbox = new JCheckBox("Enable the color chooser below", true); |
| 61 | + checkbox.addItemListener(e -> chooser.setEnabled(checkbox.isSelected())); |
43 | 62 |
|
44 | | - @Override |
45 | | - public void init() { |
46 | | - this.chooser = new JColorChooser(); |
47 | | - this.checkbox = new JCheckBox("Enable the color chooser below", true); |
48 | | - this.checkbox.addItemListener(this); |
49 | | - add(BorderLayout.NORTH, this.checkbox); |
50 | | - add(BorderLayout.CENTER, this.chooser); |
51 | | - } |
| 63 | + frame.add(chooser, BorderLayout.SOUTH); |
| 64 | + frame.add(checkbox, BorderLayout.NORTH); |
| 65 | + frame.pack(); |
52 | 66 |
|
53 | | - public void itemStateChanged(ItemEvent event) { |
54 | | - this.chooser.setEnabled(this.checkbox.isSelected()); |
| 67 | + return frame; |
55 | 68 | } |
| 69 | + |
56 | 70 | } |
0 commit comments