Trouble configuring the AWT file chooser [message #991804] |
Thu, 20 December 2012 08:36 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
I am using a FileChooser in two places. In one place I directly create a new FileChooser instance as described in this thread. In the other place I use a FileChooserField in a form.
In both cases I am able to set the default path, the default file name, the file extensions to use in the extension drop down box.
However, I think the default file chooser is ugly as sin, so I added the following code to my SwingEnvironment class to use the native windows file dialog instead:
@Override
public ISwingScoutFileChooser createFileChooser(Window w, IFileChooser fc) {
ISwingScoutFileChooser ui = new SwingScoutFileChooser(this, fc, w, true);
decorate(fc, ui);
return ui;
}
This works and lets me use the windows file dialog, however, it seems that this ignores any parameters I set on the file chooser.
- I cannot set a default directory (it seems the file dialog under windows 7 manages that on its own)
- I cannot set the extension for the extension drop down box (I always have the single entry "All files (*.*)" in there. Instead, the extension I define are used as title text for the FileDialog
- I does honour the filename that I set
Is there something more I need to do to make sure the FileChooser.setXxxx() methods have an effect for the native (AWT) file chooser? If not, I can live with not being able to set a specific directory and just having the file dialog use the last one I selected a file from. I can live with not being able to populate the extension filter dropdown, but the extensions showing in the title bar is truly annoying!
Is there a way to get rid of the extensions from the title bar?
|
|
|
|
Re: Trouble configuring the AWT file chooser [message #996928 is a reply to message #993397] |
Thu, 03 January 2013 08:11 |
Urs Beeli Messages: 573 Registered: October 2012 Location: Bern, Switzerland |
Senior Member |
|
|
Adrian
Thanks for your suggestion, I've been able to fix the title problem using this approach. It's a shame that SwingScoutFileChooser.showFileChooserSwing and SwingScoutFileChooser.showFileChooserAWT are private, otherwise it would have been very easy to just have my own file chooser inherit from SwingScoutFileChooser and then overwrite showFileChooserAWT. On the other hand, the class is not so big that having an almost 1:1 copy of the code will be a huge problem.
However, it seems that there is no way to adjust the file extension filter dropdown content for the AWT version of the file chooser (but I can live with that limitation).
Cheers
/urs
[Updated on: Thu, 03 January 2013 08:31] Report message to a moderator
|
|
|
|
|
Re: Trouble configuring the AWT file chooser [message #1001505 is a reply to message #997076] |
Wed, 16 January 2013 20:57 |
Ken Lee Messages: 97 Registered: March 2012 |
Member |
|
|
Hi Urs,
I can't see any reason too why the methods showFileChooserSwing and showFileChooserAWT should have the private modifier since this limits the extensibility of the file chooser. It makes sense to declare the modifier as protected to allow them to be exchanged by another implementation.
Furthermore, it would probably be reasonable to move the code
if (m_owner instanceof Dialog) {
dlg = new FileDialog((Dialog) m_owner, buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
}
else if (m_owner instanceof Frame) {
dlg = new FileDialog((Frame) m_owner, buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
}
else {
dlg = new FileDialog(new Frame(), buf.toString(), openMode ? FileDialog.LOAD : FileDialog.SAVE);
}
to a protected factory method. In your case you could ignore the string buffer containing the file extension and leave or set a different title for the dialog.
I'm going to assign the Bugzilla 397381 to me.
Cheers,
Ken
|
|
|
|
Powered by
FUDForum. Page generated in 0.03963 seconds