Path: blob/master/test/jdk/javax/swing/JFileChooser/6342301/bug6342301.java
41153 views
/*1* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 634230125@summary Bad interaction between setting the ui and file filters in JFileChooser26@author Pavel Porvatov27*/2829import javax.swing.*;30import javax.swing.plaf.ComponentUI;31import javax.swing.plaf.metal.MetalFileChooserUI;32import javax.swing.plaf.metal.MetalLookAndFeel;33import java.io.File;3435public class bug6342301 {36private static String tempDir;3738public static void main(String[] args) throws Exception {39tempDir = System.getProperty("java.io.tmpdir");4041if (tempDir.length() == 0) { //'java.io.tmpdir' isn't guaranteed to be defined42tempDir = System.getProperty("user.home");43}4445System.out.println("Temp directory: " + tempDir);4647UIManager.setLookAndFeel(new MetalLookAndFeel());4849SwingUtilities.invokeAndWait(new Runnable() {50public void run() {51HackedFileChooser openChooser = new HackedFileChooser();5253openChooser.setUI(new MetalFileChooserUI(openChooser));54openChooser.setCurrentDirectory(new File(tempDir));55}56});57}5859private static class HackedFileChooser extends JFileChooser {60public void setUI(ComponentUI newUI) {61super.setUI(newUI);62}63}64}656667