This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 35095 - JFileChooser.getApproveButtonText() returns null
Summary: JFileChooser.getApproveButtonText() returns null
Status: CLOSED FIXED
Alias: None
Product: qa
Classification: Unclassified
Component: Code (show other bugs)
Version: 3.x
Hardware: PC All
: P3 blocker (vote)
Assignee: issues@qa
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-23 12:31 UTC by berndq
Modified: 2011-02-17 09:30 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description berndq 2003-07-23 12:31:38 UTC
Ok, it gives a workaround for Jemmy:

 >     public String getApproveButtonText() {
 >       if(approveButtonText==null){
 > 		return getUI().getApproveButtonText(this);
 > 	}else{
 > 		return approveButtonText;
 > 	}

    public JButton getApproveButton() {
        String aText = getApproveButtonText();
        if(aText == null) {
            aText =
getUI().getApproveButtonText(this);
        }
        if(aText != null) {
            return((JButton)innerSearcher.
                   findComponent(new
ButtonFinder(aText)));
        } else {
            throw(new
JemmyException("JFileChooser.getApproveButtonText()
and " +
                                    
"JFileChooser.getUI().getApproveButtonText()" + 
                                     "return null"));
        }
    }
Comment 1 berndq 2003-07-23 12:33:28 UTC
I digged into it and it looks like a bug in the swing
JFileChooser.getApproveButtonText:

-----------------------------
	JFileChooser chooser = new JFileChooser();
	chooser.showOpenDialog(mFrame);
	System.out.println(chooser.getApproveButtonText());
-----------------------------

prints "null" to stdout.



the javadoc for JFileChosser.getApproveButtonText says:
  "Returns the text used in the ApproveButton in the FileChooserUI. If
null,
the UI object will 
  determine the button's text. Typically, this would be "Open" or "Save"."

What means "If null"?

If you look at the source:

    public String getApproveButtonText() {
	return approveButtonText;
    }

approveButtonText is defined as instance variable of JFileChooser:
    private String approveButtonText = null;

So I guess this should be something like:
    public String getApproveButtonText() {
      if(approveButtonText==null){
		return getUI().getApproveButtonText(this);
	}else{
		return approveButtonText;
	}
    }
   // which does not take care of property changes

or
    public String getApproveButtonText() {
      if(approveButtonText==null){
		setApproveButtonText(getUI().getApproveButtonText(this));
	}else{
		return approveButtonText;
	}
    }
   // which does not take care about changed text in the button


This code
		JFileChooser chooser = new JFileChooser();
	
System.out.println(chooser.getUI().getApproveButtonText(chooser));

prints the correct approved button text.



So another workaround is to use

		JFileChooser chooser = new JFileChooser();
	
chooser.setApproveButtonText(chooser.getUI().getApproveButtonText(chooser));
		chooser.showOpenDialog(mFrame);

to get the approveButtonText be set explicitley
Comment 3 Alexandre Iline 2004-10-05 00:55:06 UTC
This is the only one I am accepting: 
 "Returns the text used in the ApproveButton in the FileChooserUI. If 
null, 
the UI object will  
  determine the button's text. Typically, this would be "Open" or "Save"." 
 
Looking for _a_ button is not such a good idea - there could be more (like, 
within combobox). 
 
_Changing_ text I do not like either. 
 
Let's do it according to javadoc. 
 
Thanks.