ptolemy.gui
Class JFileChooserBugFix

java.lang.Object
  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 {
      jFileChooserBugFix.restoreBackground(background);
  }
 

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

Field Summary
private  javax.swing.text.html.HTMLEditorKit _HTMLEditorKit
          The HTMLEditorKit
 
Constructor Summary
JFileChooserBugFix()
          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

_HTMLEditorKit

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

Constructor Detail

JFileChooserBugFix

public JFileChooserBugFix()
Instantiate a JFileChooserBugFix object.

Method Detail

restoreBackground

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

Parameters:
background - The background to be restored.
See Also:
saveBackground()

saveBackground

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. http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3801

Call this method before instantiating a JFileChooser.

Returns:
the value of the previous background.