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

Deadly 提交于 2019-12-02 05:30:39

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!