JFileChooser filters

后端 未结 6 1611
悲&欢浪女
悲&欢浪女 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 09:14

    I am putting a JFileChooser in my program, but that only takes images.

    For a list of types supported by that JRE on that OS, use ImageIO.

    FileFilter imageFilter = new FileNameExtensionFilter(
        "Image files", ImageIO.getReaderFileSuffixes());
    

    Types seen - Java 1.6/Windows 7

    bmp
    jpg
    jpeg
    wbmp
    png
    gif
    

    Note: don't hard-code that list! It might change from version to version, and OS to OS. E.G.

    1. I am not surprised that Windows has support to load BMP, but does that come up in a Mac?
    2. Seeing WBMP alerted me to the existence of such a format!

    That list would have many more formats if jai was installed.

    Filter as it appears in a chooser

    Image Chooser

提交回复
热议问题