I have a method in my application called \"Save as\" which Saves the image of my application on computer my into a file. I used the JFileChooser to let the users choose thei
I think I got better solution. Will explain it with sample code fragments.
This is how I set file filter:
jFileChooser.setFileFilter(new FileNameExtensionFilter(".txt", "txt"));.
After this the main saving line:
textArea1.write(new BufferedWriter(new FileWriter(jFileChooser.getSelectedFile().getAbsolutePath() + jFileChooser.getFileFilter().getDescription().replace("All Files", ""))));.
Of course the most important is this fragment: jFileChooser.getSelectedFile().getAbsolutePath() + jFileChooser.getFileFilter().getDescription().replace("All Files", "").
The only thing I don't like is, that I could not find any method like 'getExtension' which means that You cannot have any nice description without unnecessary troubles with strings.
Ok, got it. You can do something like that:
jFileChooser.getFileFilter().toString().replaceFirst(".*extensions=\\[(.*)]]", ".$1").replaceFirst(".*AcceptAllFileFilter.*", "").
Unfortunately it's not so beautiful, but seems to work like a charm.