alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.core;

import java.awt.BorderLayout;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.plaf.FileChooserUI;
import javax.swing.plaf.metal.MetalFileChooserUI;
import org.openide.ErrorManager;

/**
 * Workaround for issue 34879 - race condition in WindowsFileChooserUI on XP
 * with JDK 1.4.  Sometimes WindowsFileChooserUI tries to create icons from
 * null images.  It is intermittent, and seems to be system dependent; for 
 * some users, the older hack of creating JFileChoosers in a loop until one
 * did not fail worked, but for other users it was simply always broken.
 * 

* This class will "warm up" WindowsFileChooserUI, letting it fail a few * times so it gets icons loaded before the user actually tries to display * a file chooser. Not pretty, but the IDE is unusable otherwise. *

* When we are only supporting JDK 1.5, this class can be removed - it will * only be called on 1.4/Windows L&F. * * @see WarmUpSupport - it is invoked from there * @author Tim Boudreau */ class Issue38479Workaround extends JFileChooser { /** Creates a new instance of Issue38479Workaround */ private Issue38479Workaround() { } public static void run() { JFrame jf = new JFrame(); jf.getContentPane().setLayout(new BorderLayout()); jf.getContentPane().add(new Issue38479Workaround()); jf.pack(); //Trigger updateUI() without actually displaying the chooser jf.dispose(); } public void updateUI() { try { super.updateUI(); } catch (NullPointerException npe) { for (int i=0; i < 7; i++) { try { npe = null; try { Thread.currentThread().sleep(100); } catch (InterruptedException ie) { break; } super.updateUI(); break; } catch (NullPointerException npe2) { npe = npe2; } } if (npe != null) { ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Repeated failures loading file chooser UI. All file" + //NOI18N "choosers will use MetalFileChooserUI instead"); //NOI18N //Failover - have to do something - for one user who tested this //patch, it simply would never succeed UIManager.put("FileChooserUI", //NOI18N "javax.swing.plaf.metal.MetalFileChooserUI"); //NOI18N } } } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.