本文整理匯總了Java中javax.swing.filechooser.FileNameExtensionFilter.getExtensions方法的典型用法代碼示例。如果您正苦於以下問題:Java FileNameExtensionFilter.getExtensions方法的具體用法?Java FileNameExtensionFilter.getExtensions怎麽用?Java FileNameExtensionFilter.getExtensions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.filechooser.FileNameExtensionFilter
的用法示例。
在下文中一共展示了FileNameExtensionFilter.getExtensions方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addChoosableFileFilter
import javax.swing.filechooser.FileNameExtensionFilter; //導入方法依賴的package包/類
@Override
public void addChoosableFileFilter(FileFilter filter) {
super.addChoosableFileFilter(filter);
if (!FX_AVAILABLE || filter == null) {
return;
}
if (filter.getClass().equals(FileNameExtensionFilter.class)) {
FileNameExtensionFilter f = (FileNameExtensionFilter) filter;
List<String> ext = new ArrayList<>();
for (String extension : f.getExtensions()) {
ext.add(extension.replaceAll("^\\*?\\.?(.*)$", "*.$1"));
}
fileChooser.getExtensionFilters()
.add(new FileChooser.ExtensionFilter(f.getDescription(), ext));
}
}
示例2: addExtensionIfRequired
import javax.swing.filechooser.FileNameExtensionFilter; //導入方法依賴的package包/類
/**
* Adds the extension to the file if required
*
* @param file
* @param fileFilter
* @return File
*/
private File addExtensionIfRequired(File file, FileFilter fileFilter) {
String name = file.getName();
// If there is an extension
if (name.indexOf('.', name.length() - 4) >= 0) {
return file;
}
if (fileFilter instanceof FileNameExtensionFilter) {
FileNameExtensionFilter extensions = (FileNameExtensionFilter) fileFilter;
return new File(file.getAbsolutePath() + '.' + extensions.getExtensions()[0]);
}
return file;
}
示例3: setFileFilter
import javax.swing.filechooser.FileNameExtensionFilter; //導入方法依賴的package包/類
@Override
public void setFileFilter(FileFilter filter) {
super.setFileFilter(filter);
removeImagePreview();
if (filter instanceof FileNameExtensionFilter) {
FileNameExtensionFilter fileNameExtensionFilter = (FileNameExtensionFilter) filter;
String[] extensions = fileNameExtensionFilter.getExtensions();
for (String extension : extensions) {
if (FileUtil.hasTextureExtension(extension)) {
addImagePreview();
}
}
}
}