Path: blob/master/test/jdk/javax/swing/JFileChooser/4150029/bug4150029.java
41153 views
/*1* Copyright (c) 2010, 2018, 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/*24bug 4150029 800608725summary BackSpace keyboard button does not lead to parent directory26author Oleg Mokhovikov27*/2829import jdk.test.lib.Platform;3031import javax.swing.*;32import java.io.File;33import java.io.IOException;3435public class bug4150029 extends JApplet {36private boolean res;3738public void init() {39if (Platform.isOSX()) {40try {41UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");42} catch (Exception e) {43throw new RuntimeException(e);44}45}4647String tmpDir = System.getProperty("java.io.tmpdir");4849if (tmpDir.length() == 0) {//'java.io.tmpdir' isn't guaranteed to be defined50tmpDir = System.getProperty("user.home");51}5253System.out.println("Temp directory: " + tmpDir);5455File testDir = new File(tmpDir, "testDir");5657testDir.mkdir();5859File subDir = new File(testDir, "subDir");6061subDir.mkdir();6263System.out.println("Created directory: " + testDir);64System.out.println("Created sub-directory: " + subDir);6566JFileChooser fileChooser = new JFileChooser(testDir);6768fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);6970try {71res = fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION ||72testDir.getCanonicalPath().equals(fileChooser.getSelectedFile().getCanonicalPath());73} catch (IOException e) {74res = false;7576e.printStackTrace();77}7879try {80subDir.delete();81testDir.delete();82} catch (SecurityException e) {83e.printStackTrace();84}85}8687public void destroy() {88if (!res) {89throw new RuntimeException("BackSpace keyboard button does not lead to parent directory");90}91}92}939495