JFileChooser filters

后端 未结 6 1609
悲&欢浪女
悲&欢浪女 2020-11-29 08:14

I am putting a JFileChooser in my program, but that only takes images. So I decided to add filters:

Code

import javax.swing.*;

public c         


        
6条回答
  •  北海茫月
    2020-11-29 08:54

    You are using wrong ImageFiler class :-)

    The ImageFilter from tutorial is not from java.awt package you are importing. This ImageFilter must implement javax.swing.filechooser.FileFilter.

    Please check if there is other ImageFilter class defined in tutorial and use it.

    Example of proper filefilter:

    new JFileChooser().addChoosableFileFilter(new FileFilter() {
    
            @Override
            public boolean accept(File f) {
                // TODO Auto-generated method stub
                return f.getName().endsWith(".jpg");
            }
    
            @Override
            public String getDescription() {
                return "JPEG files";
            }
    
        });
    

提交回复
热议问题