It is necessary that when a file is selected in JFileChooser file is displayed without an extension. How? Maybe there is a better way than to inherit JFileChooser ?

I use this code here:

 fc.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { File selectedFile = fc.getSelectedFile(); String path = selectedFile.getPath(); path=FilenameUtils.removeExtension(path); fc.setSelectedFile(new File(path)); } }); 

But in this case, the selection marker jumps up. And JFileChooser returns an incorrect file name (returns a file without an extension)

    1 answer 1

    Answered at stackoverflow.com:

     fc = new JFileChooser() { @Override public void setSelectedFile(File file) { super.setSelectedFile(file); ((BasicFileChooserUI) getUI()).setFileName(getName(file)); } };