Class JFileChooserBugFix

  extended by ptolemy.gui.JFileChooserBugFix

public class JFileChooserBugFix
extends java.lang.Object

A workaround for a JFileChooser bug.

This class is necessary to work around a bug under Windows where the "common places" portion of the JFileChooser dialog is affected by the background color of a component. Sun has acknowledged the bug as #6817933. See also "open dialog, common places pane has white box instead of text."

Every time JFileChooser is instantiated, saveBackground() should be called so that the background is properly set. Then, in a finally clause, restoreBackground() should be called. For example:

  // Swap backgrounds and avoid white boxes in "common places" dialog
  JFileChooserBugFix jFileChooserBugFix = new JFileChooserBugFix();
  Color background = null;
  try {
      background = jFileChooserBugFix.saveBackground();
      JFileChooser fileDialog = new JFileChooser();
      // Do the usual JFileChooser song and dance . . .
  } finally {

Ptolemy II 8.0
$Id: 59167 2010-09-21 17:08:02Z cxh $
Christopher Brooks
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Field Summary
private  javax.swing.text.html.HTMLEditorKit _HTMLEditorKit
          The HTMLEditorKit
Constructor Summary
          Instantiate a JFileChooserBugFix object.
Method Summary
 void restoreBackground(java.awt.Color background)
          Restore the background.
 java.awt.Color saveBackground()
          Set the background to the value of the ToolBar.shadow property and return the previous background.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


private javax.swing.text.html.HTMLEditorKit _HTMLEditorKit
The HTMLEditorKit

Constructor Detail


public JFileChooserBugFix()
Instantiate a JFileChooserBugFix object.

Method Detail


public void restoreBackground(java.awt.Color background)
Restore the background.

background - The background to be restored.
See Also:


public java.awt.Color saveBackground()
Set the background to the value of the ToolBar.shadow property and return the previous background.

Avoid a problem under Windows where the common places pane on the left of the file browser dialog has white boxes because the background is set to white.

Call this method before instantiating a JFileChooser.

the value of the previous background.