java - JFileChooser save dialog filename is modified or acted upon before approveSelection() is called -


i have filesaver class extends jfilechooser class. constructor defines file filters, sets default file filter , calls setacceptallfilefilterused(false). when user clicks button, filesaver object created , showsavedialog() called it. filesaver class overrides approveselection() can validate filename entered before calling super.approveselection().

this fine filenames entered, if filename contains question mark ("?") or asterisk ("*") approveselection() not called , new file filter created (and appears set while program treats file filter previous setting) filename description. possible treat these filenames others (such approveselection() called , selected file set accordingly)?

also, seems though filename containing forward slash ("/") treated path relative current directory , getselectedfile().getname() returns part of filename after slash (or removing slash @ end of filename) , part before appended directory path. possible approveselection() retrieve full filename validation , not alter directory?

try add class on jfilechooser class, class implements getapproveselectionaction method of windowsfilechooserui:

   public class myfilechooser extends jfilechooser{         @override       protected void setui(componentui newui) {         super.setui(new customfilechooserui(this));       }          private static boolean isglobpattern(string filename) {                 return ((file.separatorchar == '\\' && (filename.indexof('*') >= 0                                                           || filename.indexof('?') >= 0))                         || (file.separatorchar == '/' && (filename.indexof('*') >= 0                                                           || filename.indexof('?') >= 0                                                           || filename.indexof('[') >= 0)));        }        public class customfilechooserui extends windowsfilechooserui {                  jfilechooser jfilechooser;                  public customfilechooserui(jfilechooser b) {                   super(b);                   jfilechooser = b;                 }                  @override                 protected void createmodel() {                   super.createmodel();                 }                  @override                 public action getapproveselectionaction() {                   return new approveselectionaction() {                     @override                     public void actionperformed(actionevent e) {                       string filename = getfilename();                       if(isglobpattern(filename)){                         // code here                         return;                       }                       super.actionperformed(e);                     }                   };                 }         }  } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -