Skip to content

Commit bbda090

Browse files
author
duke
committed
Backport be1dd275a4b4fcae00e4c3c48b3e8e4b1d84ba2b
1 parent cce9336 commit bbda090

File tree

2 files changed

+58
-68
lines changed

2 files changed

+58
-68
lines changed

test/jdk/javax/swing/JColorChooser/Test4759934.html

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2008, 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,60 +21,87 @@
2121
* questions.
2222
*/
2323

24-
/*
25-
* @test
26-
* @bug 4759934
27-
* @summary Tests windows activation problem
28-
* @author Andrey Pikalev
29-
* @run applet/manual=yesno Test4759934.html
30-
*/
31-
3224
import java.awt.Color;
3325
import java.awt.Component;
3426
import java.awt.Window;
3527
import java.awt.event.ActionEvent;
3628
import java.awt.event.ActionListener;
37-
import javax.swing.JApplet;
3829
import javax.swing.JButton;
3930
import javax.swing.JColorChooser;
4031
import javax.swing.JDialog;
4132
import javax.swing.JFrame;
4233

43-
public class Test4759934 extends JApplet implements ActionListener {
34+
/*
35+
* @test
36+
* @bug 4759934
37+
* @library /java/awt/regtesthelpers
38+
* @build PassFailJFrame
39+
* @summary Tests windows activation problem
40+
* @run main/manual Test4759934
41+
*/
42+
public class Test4759934 {
4443
private static final String CMD_DIALOG = "Show Dialog"; // NON-NLS: first button
4544
private static final String CMD_CHOOSER = "Show ColorChooser"; // NON-NLS: second button
4645

47-
private final JFrame frame = new JFrame("Test"); // NON-NLS: frame title
46+
private static JFrame frame;
4847

49-
public void init() {
50-
show(this.frame, CMD_DIALOG);
51-
}
48+
private static ActionListener al = new ActionListener() {
49+
@Override
50+
public void actionPerformed(ActionEvent event) {
51+
String command = event.getActionCommand();
52+
if (CMD_DIALOG.equals(command)) {
53+
JDialog dialog = new JDialog(frame, "Dialog"); // NON-NLS: dialog title
54+
dialog.setLocation(200, 0);
55+
show(dialog, CMD_CHOOSER, true);
56+
}
57+
else if (CMD_CHOOSER.equals(command)) {
58+
Object source = event.getSource();
59+
Component component = (source instanceof Component)
60+
? (Component) source
61+
: null;
5262

53-
public void actionPerformed(ActionEvent event) {
54-
String command = event.getActionCommand();
55-
if (CMD_DIALOG.equals(command)) {
56-
JDialog dialog = new JDialog(this.frame, "Dialog"); // NON-NLS: dialog title
57-
dialog.setLocation(200, 0);
58-
show(dialog, CMD_CHOOSER);
63+
JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title
64+
}
5965
}
60-
else if (CMD_CHOOSER.equals(command)) {
61-
Object source = event.getSource();
62-
Component component = (source instanceof Component)
63-
? (Component) source
64-
: null;
66+
};
6567

66-
JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title
67-
}
68+
public static void main(String[] args) throws Exception {
69+
String instructions = "1. Press button \"Show Dialog\" at the frame \"Test\" and\n" +
70+
" the dialog with button \"Show ColorChooser\" should appears.\n" +
71+
"2. Press button \"Show ColorChooser\" at the dialog \"Dialog\" and\n" +
72+
" the colorchooser should appears.\n" +
73+
"3. Press the button \"Cancel\" of colorchooser.\n" +
74+
" If the focus will come to the frame \"Test\" then test fails.\n" +
75+
" If the focus will come to the dialog \"Dialog\" then test passes.";
76+
77+
PassFailJFrame.builder()
78+
.title("Test4759934")
79+
.instructions(instructions)
80+
.rows(5)
81+
.columns(40)
82+
.testTimeOut(10)
83+
.testUI(Test4759934::test)
84+
.build()
85+
.awaitAndCheck();
6886
}
6987

70-
private void show(Window window, String command) {
88+
public static JFrame test() {
89+
frame = new JFrame("ColorChooser dialog on button press test");
90+
show(frame, CMD_DIALOG, false);
91+
return frame;
92+
}
93+
94+
private static void show(Window window, String command, boolean setVisible) {
7195
JButton button = new JButton(command);
7296
button.setActionCommand(command);
73-
button.addActionListener(this);
97+
button.addActionListener(al);
98+
7499
button.setFont(button.getFont().deriveFont(64.0f));
75100

76101
window.add(button);
77102
window.pack();
78-
window.setVisible(true);
103+
if (setVisible) {
104+
window.setVisible(true);
105+
}
79106
}
80107
}

0 commit comments

Comments
 (0)