Added
Link Here
|
1 |
/* |
2 |
* Issue38479Workaround.java |
3 |
* |
4 |
* Created on August 26, 2004, 2:43 PM |
5 |
*/ |
6 |
|
7 |
package org.netbeans.core; |
8 |
|
9 |
import java.awt.BorderLayout; |
10 |
import javax.swing.JFileChooser; |
11 |
import javax.swing.JFrame; |
12 |
import javax.swing.UIManager; |
13 |
import javax.swing.plaf.FileChooserUI; |
14 |
import javax.swing.plaf.metal.MetalFileChooserUI; |
15 |
|
16 |
/** |
17 |
* Workaround for issue 34879 - sometimes the WinXP file chooser UI |
18 |
* tries to create image icons for the file chooser buttons before |
19 |
* it has loaded its images, calls new ImageIcon(null) and throws an |
20 |
* NPE. A second call usually succeeds, but this is recently reported |
21 |
* to fail a second time, so we try it several times. |
22 |
* <p> |
23 |
* This class will "warm up" WindowsFileChooserUI, letting it fail a few |
24 |
* times if it needs to. |
25 |
* |
26 |
* @author Tim Boudreau |
27 |
*/ |
28 |
public class Issue38479Workaround extends JFileChooser { |
29 |
|
30 |
/** Creates a new instance of Issue38479Workaround */ |
31 |
public Issue38479Workaround() { |
32 |
} |
33 |
|
34 |
public static void run() { |
35 |
System.err.println("Running workaround for issue 38479"); |
36 |
JFrame jf = new JFrame(); |
37 |
jf.getContentPane().setLayout(new BorderLayout()); |
38 |
jf.getContentPane().add(new Issue38479Workaround()); |
39 |
//Triggers updateUI() |
40 |
jf.pack(); |
41 |
jf.dispose(); |
42 |
} |
43 |
|
44 |
public void updateUI() { |
45 |
try { |
46 |
System.err.println("Forcing file chooser UI to pre-initialize"); |
47 |
super.updateUI(); |
48 |
} catch (NullPointerException npe) { |
49 |
for (int i=0; i < 5; i++) { |
50 |
System.err.println("Try number " + i); |
51 |
try { |
52 |
npe = null; |
53 |
try { |
54 |
Thread.currentThread().sleep(50); |
55 |
} catch (InterruptedException ie) { |
56 |
break; |
57 |
} |
58 |
super.updateUI(); |
59 |
break; |
60 |
} catch (NullPointerException npe2) { |
61 |
npe = npe2; |
62 |
} |
63 |
} |
64 |
if (npe != null) { |
65 |
System.err.println("Complete failure. Defaulting all file choosers" + |
66 |
"to use MetalFileChooserUI"); |
67 |
//Failover - have to do something |
68 |
UIManager.put("FileChooserUI", |
69 |
"javax.swing.plaf.metal.MetalFileChooserUI"); //NOI18N |
70 |
setUI ((FileChooserUI) MetalFileChooserUI.createUI(this)); |
71 |
} |
72 |
} |
73 |
} |
74 |
} |