本文整理匯總了Java中javax.swing.filechooser.FileFilter類的典型用法代碼示例。如果您正苦於以下問題:Java FileFilter類的具體用法?Java FileFilter怎麽用?Java FileFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileFilter類屬於javax.swing.filechooser包,在下文中一共展示了FileFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: actionPerformed
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser(DocOpenAction.lastOpenedFileLocation);
chooser.setMultiSelectionEnabled(true);
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File file) {
DocOpenAction.lastOpenedFileLocation = file.getParent();
return
file.isDirectory() ||
(file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".pdf"));
}
@Override
public String getDescription() {
return resources.getString("FILE_FILTER_PDF");
}
});
if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
PdfJumbler.openFiles(list, -1, Arrays.asList(chooser.getSelectedFiles()));
}
}
示例2: resetFileFilters
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
private void resetFileFilters(boolean enableFilters,
boolean showExtensionInDescription) {
chooser.resetChoosableFileFilters();
if (enableFilters) {
FileFilter jpgFilter = createFileFilter(
"JPEG Compressed Image Files",
showExtensionInDescription, "jpg");
FileFilter gifFilter = createFileFilter("GIF Image Files",
showExtensionInDescription, "gif");
FileFilter bothFilter = createFileFilter("JPEG and GIF Image Files",
showExtensionInDescription, "jpg",
"gif");
chooser.addChoosableFileFilter(bothFilter);
chooser.addChoosableFileFilter(jpgFilter);
chooser.addChoosableFileFilter(gifFilter);
}
}
示例3: btn_AdicionarActionPerformed
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
private void btn_AdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AdicionarActionPerformed
// TODO add your handling code here:
JFileChooser fc = new JFileChooser();
FileFilter imageFilter = new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes());
fc.setFileFilter(imageFilter);
int result = fc.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION){
try {
String path = fc.getSelectedFile().getAbsolutePath();
imagens.add(new ImageIcon(path));
if(!auxImagens.contains(imagens.get(imagens.size() - 1))){
auxImagens.add(imagens.get(imagens.size() - 1));
}
JOptionPane.showMessageDialog(this, "Imagem carregada com sucesso!");
} catch(Exception e){
JOptionPane.showMessageDialog(null, "Ocorreu um erro ao carregar a imagem!", "Erro", JOptionPane.ERROR_MESSAGE);
}
}
jsl_Slider.setMaximum(Math.max(0, imagens.size() - 1));
}
示例4: btn_CarregarImagemActionPerformed
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
private void btn_CarregarImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CarregarImagemActionPerformed
// TODO add your handling code here:
JFileChooser fc = new JFileChooser();
FileFilter imageFilter = new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes());
fc.setFileFilter(imageFilter);
int result = fc.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION){
try {
String path = fc.getSelectedFile().getAbsolutePath();
imagens.add(new ImageIcon(path));
JOptionPane.showMessageDialog(this, "Imagem carregada com sucesso!");
} catch(Exception e){
JOptionPane.showMessageDialog(null, "Ocorreu um erro ao carregar a imagem!", "Erro", JOptionPane.ERROR_MESSAGE);
}
}
}
示例5: loadFromXML
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
synchronized public void loadFromXML() {
this.setProcessingEnabled(false);
JFileChooser c = new JFileChooser(this.getLastRNNXMLFile());
FileFilter filter = new FileNameExtensionFilter("XML File", "xml");
c.addChoosableFileFilter(filter);
c.setFileFilter(filter);
c.setSelectedFile(new File(this.getLastRNNXMLFile()));
int ret = c.showOpenDialog(chip.getAeViewer());
if (ret != JFileChooser.APPROVE_OPTION) {
return;
}
File f = c.getSelectedFile();
try {
this.rnnetwork.loadFromXML(f);
this.setLastRNNXMLFile(f.toString());
putString("lastRNNXMLFile", this.getLastRNNXMLFile());
// this.testNumpyData.rnnetwork.loadFromXML(c.getSelectedFile()); //debug
} catch (Exception e) {
log.log(Level.WARNING, "Couldn't upload the xml file, please check. Caught exception {0}", e);
}
this.resetFilter();
}
示例6: SaveDialog
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
/**
* Creates a dialog to choose a file to load.
*
* @param freeColClient The {@code FreeColClient} for the game.
* @param frame The owner frame.
* @param directory The directory to display when choosing the file.
* @param fileFilters The available file filters in the dialog.
* @param defaultName Name of the default save game file.
*/
public SaveDialog(FreeColClient freeColClient, JFrame frame,
File directory, FileFilter[] fileFilters, String defaultName) {
super(freeColClient, frame);
final JFileChooser fileChooser = new JFileChooser(directory);
if (fileFilters.length > 0) {
for (FileFilter fileFilter : fileFilters) {
fileChooser.addChoosableFileFilter(fileFilter);
}
fileChooser.setFileFilter(fileFilters[0]);
fileChooser.setAcceptAllFileFilterUsed(false);
}
fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setFileHidingEnabled(false);
fileChooser.setSelectedFile(new File(defaultName));
fileChooser.addActionListener((ActionEvent ae) ->
setValue((JFileChooser.APPROVE_SELECTION
.equals(ae.getActionCommand()))
? fileChooser.getSelectedFile() : cancelFile));
List<ChoiceItem<File>> c = choices();
initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
示例7: register
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
public static void register(Project project,
AntProjectHelper helper,
ReferenceHelper refHelper,
ListComponent list,
ButtonModel addJar,
ButtonModel addLibrary,
ButtonModel addAntArtifact,
ButtonModel remove,
ButtonModel moveUp,
ButtonModel moveDown,
ButtonModel edit,
Document libPath,
ClassPathUiSupport.Callback callback,
String[] antArtifactTypes,
FileFilter filter,
int fileSelectionMode) {
register(project, helper, refHelper, list, addJar, addLibrary, addAntArtifact, remove, moveUp, moveDown, edit, false, libPath, callback, antArtifactTypes, filter, fileSelectionMode);
}
示例8: btnRefFileBrowseActionPerformed
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
private void btnRefFileBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefFileBrowseActionPerformed
JFileChooser fc = new JFileChooser(wd);
FileFilter filter = new FileFilter() {
public boolean accept(File f) {
return f.getName().endsWith(".xml");
}
public String getDescription() {
return "XML files";
}
};
fc.setFileFilter(filter);
int result = fc.showOpenDialog(this);
if(result == JFileChooser.APPROVE_OPTION) {
txtRefFile.setText (fc.getSelectedFile().getPath());
wd = fc.getCurrentDirectory();
}
}
示例9: createFileChooser
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
private static JFileChooser createFileChooser() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setDialogTitle(Bundle.ExportSnapshotAction_FileChooserCaption());
fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
fileChooser.setApproveButtonText(Bundle.ExportSnapshotAction_ExportButtonText());
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
fileChooser.addChoosableFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(NPSS_EXT);
}
public String getDescription() {
return Bundle.ExportSnapshotAction_NpssFileFilter(NPSS_EXT);
}
});
return fileChooser;
}
示例10: testRegisteredFilters
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
/**
* This test, although it is quite short, tests a lot of ascpects of default
* file filters. The resolver definition XML file contains several
* duplicities, which are detected and ignored. If this detection fails,
* filter description and {@code accept} method is changed, and it is cought
* by this test.
*/
public void testRegisteredFilters() {
List<FileFilter> list = FileFilterSupport.findRegisteredFileFilters();
assertNotNull(list);
assertFalse(list.isEmpty());
boolean found = false;
for (FileFilter filter : list) {
if (filter.getDescription().startsWith("BNM Files")) {
found = true;
checkBnmFilesFilter(filter);
}
}
assertTrue("Registered File Filter was not found.", found);
}
示例11: testSetFileFilter
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
/**
* Test of setFileFilter method, of class FileChooserBuilder.
*/
public void testSetFileFilter() {
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File f) {
return true;
}
@Override
public String getDescription() {
return "X";
}
};
FileChooserBuilder instance = new FileChooserBuilder("c");
instance.setFileFilter(filter);
assertEquals(filter, instance.createFileChooser().getFileFilter());
}
示例12: openFileDialogAndGetFile
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
private File openFileDialogAndGetFile(String tip, String key, String type, String... ext) {
File file = null;
JFileChooser c = new JFileChooser(lastNetworkFilename);
File f = new File(lastNetworkFilename);
c.setCurrentDirectory(new File(getString("lastNetworkPathname", "")));
c.setToolTipText(tip);
FileFilter filt = new FileNameExtensionFilter(type, ext);
c.addChoosableFileFilter(filt);
c.setFileFilter(filt);
c.setSelectedFile(new File(lastNetworkFilename));
int ret = c.showOpenDialog(chip.getAeViewer());
if (ret != JFileChooser.APPROVE_OPTION) {
return null;
}
lastNetworkFilename = c.getSelectedFile().toString();
putString(key, lastNetworkFilename);
lastNetworkPathname = f.getPath();
putString("lastNetworkPathname", lastNetworkPathname);
file = c.getSelectedFile();
return file;
}
示例13: getListCellRendererComponent
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
public Component getListCellRendererComponent(JList<? extends FileFilter> list, FileFilter value, int index,
boolean isSelected, boolean cellHasFocus) {
Component c = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String text = null;
if (value != null) {
text = value.getDescription();
}
//this should always be true, since SynthComboBoxUI's SynthComboBoxRenderer
//extends JLabel
assert c instanceof JLabel;
if (text != null) {
((JLabel)c).setText(text);
}
return c;
}
示例14: getSnapshotFileChooser
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
private static JFileChooser getSnapshotFileChooser() {
if (snapshotFileChooser == null) {
snapshotFileChooser = new JFileChooser();
snapshotFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
snapshotFileChooser.setMultiSelectionEnabled(false);
snapshotFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
snapshotFileChooser.setDialogTitle(Bundle.CompareSnapshotsAction_OpenChooserCaption());
snapshotFileChooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().endsWith(".nps"); // NOI18N
}
public String getDescription() {
return Bundle.CompareSnapshotsAction_OpenChooserFilter("nps"); // NOI18N
}
});
snapshotFileChooser.setAcceptAllFileFilterUsed(false);
}
return snapshotFileChooser;
}
示例15: onExportFilenameBrowseClick
import javax.swing.filechooser.FileFilter; //導入依賴的package包/類
private void onExportFilenameBrowseClick() {
File oldFile = getExecutableFile();
JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(MercurialOptionsPanelController.class, "ACSD_ExportBrowseFolder"), oldFile); // NOI18N
fileChooser.setDialogTitle(NbBundle.getMessage(MercurialOptionsPanelController.class, "ExportBrowse_title")); // NOI18N
fileChooser.setMultiSelectionEnabled(false);
FileFilter[] old = fileChooser.getChoosableFileFilters();
for (int i = 0; i < old.length; i++) {
FileFilter fileFilter = old[i];
fileChooser.removeChoosableFileFilter(fileFilter);
}
fileChooser.showDialog(panel, NbBundle.getMessage(MercurialOptionsPanelController.class, "OK_Button")); // NOI18N
File f = fileChooser.getSelectedFile();
if (f != null) {
panel.exportFilenameTextField.setText(f.getAbsolutePath());
}
}