author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 7961 | 252a7e8c37c1 |
permissions | -rw-r--r-- |
7961
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
7961
diff
changeset
|
2 |
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
7961
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
4 |
* |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
8 |
* |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
13 |
* accompanied this code). |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
14 |
* |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
18 |
* |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
21 |
* questions. |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
22 |
*/ |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
23 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
24 |
/* @test |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
25 |
@bug 6342301 |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
26 |
@summary Bad interaction between setting the ui and file filters in JFileChooser |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
27 |
@author Pavel Porvatov |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
28 |
*/ |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
29 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
30 |
import javax.swing.*; |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
31 |
import javax.swing.plaf.ComponentUI; |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
32 |
import javax.swing.plaf.metal.MetalFileChooserUI; |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
33 |
import javax.swing.plaf.metal.MetalLookAndFeel; |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
34 |
import java.io.File; |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
35 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
36 |
public class bug6342301 { |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
37 |
private static String tempDir; |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
38 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
39 |
public static void main(String[] args) throws Exception { |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
40 |
tempDir = System.getProperty("java.io.tmpdir"); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
41 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
42 |
if (tempDir.length() == 0) { //'java.io.tmpdir' isn't guaranteed to be defined |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
43 |
tempDir = System.getProperty("user.home"); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
44 |
} |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
45 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
46 |
System.out.println("Temp directory: " + tempDir); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
47 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
48 |
UIManager.setLookAndFeel(new MetalLookAndFeel()); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
49 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
50 |
SwingUtilities.invokeAndWait(new Runnable() { |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
51 |
public void run() { |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
52 |
HackedFileChooser openChooser = new HackedFileChooser(); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
53 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
54 |
openChooser.setUI(new MetalFileChooserUI(openChooser)); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
55 |
openChooser.setCurrentDirectory(new File(tempDir)); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
56 |
} |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
57 |
}); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
58 |
} |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
59 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
60 |
private static class HackedFileChooser extends JFileChooser { |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
61 |
public void setUI(ComponentUI newUI) { |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
62 |
super.setUI(newUI); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
63 |
} |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
64 |
} |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
diff
changeset
|
65 |
} |