public class JFileChooserBugFix
extends java.lang.Object
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(); PtFileChooser ptFileChooser = new PtFileChooser(); // Do the usual JFileChooser song and dance . . . } finally { jFileChooserBugFix.restoreBackground(background); }
Note that Java under Mac OS X has a much better
implementation of the file chooser that uses java.awt.FileDialog
instead of javax.swing.JFileChooser. Thus, under Mac OS X,
this class is typically not invoked. Under Mac OS X,
to invoke this class, either
PtGUIUtilities.useFileDialog()
or
PtGUIUtilities.macOSLookAndFeel()
should
return false. To do this, set either the
ptolemy.ptII.useFileDialog property to false or
set the ptolemy.ptII.MacOS property to false. See
PtGUIUtilities
for how to set these properties.
Constructor and Description |
---|
JFileChooserBugFix()
Instantiate a JFileChooserBugFix object.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public JFileChooserBugFix()
public void restoreBackground(java.awt.Color background)
This method is not typically called on the Mac, see the class comment.
background
- The background to be restored.saveBackground()
public java.awt.Color saveBackground()
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.
This method is not typically called on the Mac, see the class comment.