JDK-6742360 : File save dialog does not show custom approve button text first time
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-08-28
  • Updated: 2011-02-16
  • Resolved: 2009-09-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Description
FULL PRODUCT VERSION :
java version "1.6.0_10-rc"
Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b28)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP Version 5.1.2600

A DESCRIPTION OF THE PROBLEM :
When using showSaveDialog, a custom set approve button text does not appear until the second attempt.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run ApproveButtonTest. Click "Cancel" on the file chooser dialog.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The approve button text should read "Export" the first time the file chooser dialog appears.
ACTUAL -
The approve button text reads "Save", the first time the file chooser dialog appears.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

public class ApproveButtonTest {
    private static JFileChooser chooser = null;

    public static void main(final String[] args) throws Throwable {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(WindowsLookAndFeel.class.getName());
                } catch (Throwable t) {
                    t.printStackTrace();
                }
                if (chooser == null) {
                    chooser = new JFileChooser("C:/");
                }
                for (int i = 0; i < 2; i++) {
                    chooser.setApproveButtonText("Export");
                    chooser.showSaveDialog(null);
                }
                System.exit(0);
            }
        });
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
For the example above, a workaround is to insert the following before setting the approve button text:

chooser.setDialogType(JFileChooser.SAVE_DIALOG);

Comments
EVALUATION JFileChooser resets approveButton text when dialogType is changing. It's incorrect behaviour: JFileChooser shouldn't reset approveButton in such case.
28-08-2008