Skip to content

Commit 9bc2360

Browse files
author
Harshitha Onkar
committed
8371364: Refactor javax/swing/JFileChooser/FileSizeCheck.java to use Util.findComponent()
Reviewed-by: aivanov
1 parent a90fc26 commit 9bc2360

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, 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
@@ -34,7 +34,6 @@
3434
import java.util.Arrays;
3535
import java.util.Locale;
3636
import java.util.concurrent.atomic.AtomicReference;
37-
import java.util.function.Predicate;
3837

3938
import javax.swing.AbstractButton;
4039
import javax.swing.JFileChooser;
@@ -52,6 +51,8 @@
5251
* @requires (os.family == "linux")
5352
* @summary Verifies if the size of an empty file is shown as 0.0 KB
5453
* as well as checks the displayed file sizes are rounded up
54+
* @library /javax/swing/regtesthelpers
55+
* @build Util
5556
* @run main FileSizeCheck
5657
*/
5758
public class FileSizeCheck {
@@ -228,31 +229,15 @@ private static void clickDetails() {
228229
}
229230

230231
private static AbstractButton findDetailsButton(final Container container) {
231-
Component result = findComponent(container,
232+
Component result = Util.findComponent(container,
232233
c -> c instanceof JToggleButton button
233234
&& "Details".equals(button.getToolTipText()));
234235
return (AbstractButton) result;
235236
}
236237

237238
private static JTable findTable(final Container container) {
238-
Component result = findComponent(container,
239-
c -> c instanceof JTable);
239+
Component result = Util.findComponent(container,
240+
c -> c instanceof JTable);
240241
return (JTable) result;
241242
}
242-
243-
private static Component findComponent(final Container container,
244-
final Predicate<Component> predicate) {
245-
for (Component child : container.getComponents()) {
246-
if (predicate.test(child)) {
247-
return child;
248-
}
249-
if (child instanceof Container cont && cont.getComponentCount() > 0) {
250-
Component result = findComponent(cont, predicate);
251-
if (result != null) {
252-
return result;
253-
}
254-
}
255-
}
256-
return null;
257-
}
258243
}

0 commit comments

Comments
 (0)