• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange behaviour of JFileChooser

 
Suman Mummaneni
Ranch Hand
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I noticed this strange behaviour of JFileChooser(Save dialog). I created a simple save dialog using JFileChooser (if you want to try it out u can use the sample program from sun web site in the tutorial) with AllFile filter. I typed an invalid file name for example "/?<" as the file name and a very strange thing happens. The characters u types becomes your currently selected file filter. I do not know how to handel this event. If any one handeled this please send me a e-mail. I think I should report this event to sun web site as a bug in Java 1.5.0_04
(This is confusing )
 
Ed Ewing
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a feature, not a bug.

You have discovered the GlobFilter, which, according to the documentation inside the code for BasicFileChooserUI.java is:

/* A file filter which accepts file patterns containing
* the special wildcard '*' on windows, plus '?', and '[ ]' on Unix.
*/

I assume the Macintosh version works the same as Unix, but haven't tried it. Anyway, the user can use it to create a file filter on-the-fly to search through a directory for all files beggining with "foo", for example: "foo*" or "foo_0?.txt" for "foo_01.txt", "foo_02.txt", etc.

I don't know why you would want to catch this event during the program, but you could do it this way:



 
Suman Mummaneni
Ranch Hand
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ed Ewing
Thank you very much for the info. The reason I want to catch the exception is if user enter a invalid name like "/?><" which is not valid. In this case what happens is the file chooser does not return a file name since there is a wild card char"?" in the file name string. but instead add this string to the file filter which when you look at the end users perspective is not a valid behaviour. So this kinds of exceptions mus be caught and dealt with it accordingly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!