This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 38479
Collapse All | Expand All

(-)core/src/org/netbeans/core/Issue38479Workaround.java (+74 lines)
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
}
(-)core/src/org/netbeans/core/WarmUpSupport.java (+8 lines)
Lines 13-18 Link Here
13
13
14
package org.netbeans.core;
14
package org.netbeans.core;
15
15
16
import javax.swing.UIManager;
16
import org.netbeans.core.perftool.StartLog;
17
import org.netbeans.core.perftool.StartLog;
17
import org.openide.ErrorManager;
18
import org.openide.ErrorManager;
18
import org.openide.filesystems.*;
19
import org.openide.filesystems.*;
Lines 48-53 Link Here
48
49
49
    public void run() {
50
    public void run() {
50
        boolean willLog = err.isLoggable(ErrorManager.INFORMATIONAL);
51
        boolean willLog = err.isLoggable(ErrorManager.INFORMATIONAL);
52
        
53
        if (System.getProperty("java.version").indexOf("1.4") != -1 //NOI18N
54
            && "Windows".equals(UIManager.getLookAndFeel().getID())) {//NOI18N
55
                
56
            Issue38479Workaround.run();
57
        }
58
        
51
        if (willLog) {
59
        if (willLog) {
52
            err.log("starting..."); // NOI18N
60
            err.log("starting..."); // NOI18N
53
            StartLog.logStart("Warmup"); // NOI18N
61
            StartLog.logStart("Warmup"); // NOI18N

Return to bug 38479