JavaFX FileChooser: how to set file filters?

前端 未结 3 1409
梦如初夏
梦如初夏 2021-02-05 01:18

I want to set file filters in a JavaFX FileChooser but I could not find a way to do it.

My code:

  FileChooser fc = new FileChooser();
  fc.setTitle(\"M         


        
3条回答
  •  时光取名叫无心
    2021-02-05 02:02

    This is How you can do it.

    FileChooser fc=new FileChooser();
    FileChooser.ExtensionFilter fileExtensions =new FileChooser.ExtensionFilter("music files","*.mp3", "*.mp4");
    fc.getExtensionFilters().add(fileExtensions);
    List selectedFiles=fc.showOpenMultipleDialog(null);       
    if(selectedFiles!=null){
         for(int i=0;i

提交回复
热议问题