Shariq Qamar Shariq Qamar - 3 months ago 33
Java Question

Filter not working in FileDialog

I have to replace JFileChooser with FileDialog. I could not Filter out the file. Following is the code. The filter is also not visible on the Save FileDialog and also user is able to save the file file with different ext. The environment is windows 10

public class ABCDialog extends JDialog {

private String fileName = StringUtils.Empty;

public ABCDialog (Frame frame,String title) {
super(frame, title);

public String getFileName () {
return fileName;

private String setFileName () {
FileDialog file = new FileDialog(new Frame(), "Save File...", FileDialog.SAVE);
final FilenameFilter filenameFilter = (dir, name) -> name.endsWith(".txt");

return (file.getDirectory() + file.getFile());

public void setVisible(boolean visible) {
fileName = setFileName();



According to the FileDialog#setFilenameFilter JavaDoc:

Filename filters do not function in Sun's reference implementation for Microsoft Windows.

So this is expected behaviour.