void () { // when the file name changes AND has focus, then this is the user editing and not an automatic update after selecting a file. if (myFileName.hasFocus()) { // if the selected item is a file (not a directory), change the selection to the parent folder. // this is the symmetric logic as in FileSaverDialogImpl.getFile() if (myFileSystemTree.getSelectedFile() != null && !myFileSystemTree.getSelectedFile().isDirectory()) { // now switch to parent folder of the file myFileSystemTree.select(myFileSystemTree.getSelectedFile().getParent(), () -> { }); } } }