1 /*
 2  * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 4624353
27  * @summary Tests that Motif FileChooser is not able to show control buttons
28  * @key headful
29  * @run main bug4624353
30  */
31 
32 import java.awt.Component;
33 import java.awt.Container;
34 import javax.swing.JButton;
35 import javax.swing.JFileChooser;
36 import javax.swing.JFrame;
37 import javax.swing.SwingUtilities;
38 import javax.swing.UIManager;
39 
40 public class bug4624353 {
41     static volatile boolean passed = true;
42     static JFrame fr;
43     static JFileChooser fc;
44 
45     public static void main(String args[]) throws Exception {
46         UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
47 
48         try {
49             SwingUtilities.invokeAndWait(() -> {
50                 fr = new JFrame("bug4624353");
51                 fc = new JFileChooser();
52                 fc.setControlButtonsAreShown(false);
53                 fr.getContentPane().add(fc);
54                 fr.pack();
55                 fr.setVisible(true);
56 
57                 passAround(fc);
58             });
59             if (!passed) {
60                 throw new RuntimeException("Test failed");
61             }
62         } finally {
63             SwingUtilities.invokeAndWait(() -> {
64                 if (fr != null) {
65                     fr.dispose();
66                 }
67             });
68         }
69     }
70 
71     public static void passAround(Container c) {
72         Component[] list = c.getComponents();
73         if (list.length == 0) {
74             return;
75         }
76         for (int i = 0; i < list.length; i++) {
77             if (list[i] != null) {
78                 if ((list[i] instanceof JButton) &&
79                         "OK".equals(((JButton)list[i]).getText())) {
80                     passed = false;
81                     return;
82                 }
83                 passAround((Container)list[i]);
84             }
85         }
86     }
87 }