I need to display the file name without the extension in JFileChooser(open mode). How?

后端 未结 1 1032
情书的邮戳
情书的邮戳 2021-01-25 18:03

I use \'JFileChooser\' in open mode. I need to display the \'file name\' field without the extension. How?? I know the FileView. It remove extensions in file system\'s files, b

1条回答
  •  隐瞒了意图╮
    2021-01-25 18:32

    The underlying reason is that the ui doesn't use the view's name as text in the name field. Which may or may but be a good idea, don't know. If you really want that, you can do so manually, either in a subclass of JFileChooser or in a PropertyChangeListener, here's an override:

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

    Edit

    outch ... hadn't expected so much mis-behaviour of the ui :-( Problem is that all the actions re-create a file object based on the content of the textField (instead of using the selectedFile property of the chooser) Now if that string has the extension trimmed, the file isn't found. The only way out would be to replace the actions ... which might not work.

    In summary, this answer is useless, sorry.

    0 讨论(0)
提交回复
热议问题