Skip to content

Commit 78db38f

Browse files
author
Harshitha Onkar
committed
8371365: Update javax/swing/JFileChooser/bug4759934.java to use Util.findComponent()
Reviewed-by: aivanov, dnguyen, azvegint
1 parent e5c7293 commit 78db38f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

test/jdk/javax/swing/JFileChooser/bug4759934.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
* @run main bug4759934
3232
*/
3333

34+
import java.awt.Component;
35+
import java.awt.Container;
3436
import java.awt.Dialog;
3537
import java.awt.Point;
3638
import java.awt.Robot;
37-
import java.awt.event.KeyEvent;
3839
import java.awt.event.MouseEvent;
3940
import javax.swing.JButton;
4041
import javax.swing.JDialog;
@@ -72,8 +73,10 @@ public static void main(String[] args) throws Exception {
7273
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
7374
robot.delay(500);
7475

75-
robot.keyPress(KeyEvent.VK_ESCAPE);
76-
robot.keyRelease(KeyEvent.VK_ESCAPE);
76+
SwingUtilities.invokeAndWait(() -> {
77+
JButton cancelBtn = findCancelButton(jfc);
78+
cancelBtn.doClick();
79+
});
7780
robot.delay(500);
7881

7982
SwingUtilities.invokeAndWait(() -> {
@@ -121,4 +124,11 @@ private static void createDialog() {
121124
dlg.setLocation(fr.getX() + fr.getWidth() + 10, fr.getY());
122125
dlg.setVisible(true);
123126
}
127+
128+
private static JButton findCancelButton(final Container container) {
129+
Component result = Util.findComponent(container,
130+
c -> c instanceof JButton button
131+
&& "Cancel".equals(button.getText()));
132+
return (JButton) result;
133+
}
124134
}

0 commit comments

Comments
 (0)