當前位置: 首頁>>代碼示例>>Java>>正文


Java FileNameExtensionFilter類代碼示例

本文整理匯總了Java中javax.swing.filechooser.FileNameExtensionFilter的典型用法代碼示例。如果您正苦於以下問題:Java FileNameExtensionFilter類的具體用法?Java FileNameExtensionFilter怎麽用?Java FileNameExtensionFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FileNameExtensionFilter類屬於javax.swing.filechooser包,在下文中一共展示了FileNameExtensionFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: btnTomarFotoActionPerformed

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
private void btnTomarFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTomarFotoActionPerformed
    // TODO add your handling code here:
    FileNameExtensionFilter filtro = new FileNameExtensionFilter("Formatos de Archivo JPEG(*.JPG;*.JPEG)","jpg","jpeg");
    jFileChooser1.addChoosableFileFilter(filtro);
    jFileChooser1.setFileFilter(filtro);
    File Nombre =new File(txtNombre.getText()+" "+txtApellido.getText()+".jpg");
    jFileChooser1.setSelectedFile(Nombre);
    jFileChooser1.setDialogTitle("Guardar Imagen");
    File ruta = new File("C:/Imagenes");
    jFileChooser1.setCurrentDirectory(ruta);
   int returnVal = jFileChooser1.showSaveDialog(null);
    if (returnVal == jFileChooser1.APPROVE_OPTION) {
    File file = jFileChooser1.getSelectedFile();
    Highgui.imwrite(file.getPath(), frame);
} else {
    System.out.println("File access cancelled by user.");
}
}
 
開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:19,代碼來源:JDIngresarPaciente.java

示例2: btn_AdicionarActionPerformed

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的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));
}
 
開發者ID:Mentz,項目名稱:PPRCarTrade,代碼行數:21,代碼來源:TelaEditarImagensVeiculo.java

示例3: btn_CarregarImagemActionPerformed

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的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);
        }            
    }
}
 
開發者ID:Mentz,項目名稱:PPRCarTrade,代碼行數:17,代碼來源:TelaVenda.java

示例4: saveFileAs

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
public void saveFileAs()
{
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileNameExtensionFilter("Lang871 Code Files", "871")); // Setting file type filter
    fileChooser.setSelectedFile(new File("קוד.871")); // Setting suggested file name
    fileChooser.setCurrentDirectory(new File("C:\\Users\\גלעד\\Desktop\\אביב\\מסמכים\\תכנות\\Java\\src\\com\\aviv871\\edu\\Lang871")); // TODO: change to desktop and save the last location the user used

    if(fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)
    {
        File file;
        if(!fileChooser.getSelectedFile().getName().endsWith(".871")) file = new File(fileChooser.getSelectedFile() + ".871");
        else file = fileChooser.getSelectedFile();

        writeToFile(file);
        codeFile = file;
    }
}
 
開發者ID:Aviv871,項目名稱:Lang871,代碼行數:18,代碼來源:CodeEditor.java

示例5: initCxfDBNetwork

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
private ExploreNetwork initCxfDBNetwork() throws FileNotFoundException {
	ExploreNetwork cxfDBNetwork = null;

	FileChooser fc = new FileChooser();
	fc.setDialogTitle("Select a CXF file");
	fc.setFileFilter(new FileNameExtensionFilter(".cxf files", "cxf"));
	int returnVal = fc.showOpenDialog(null);

	if (returnVal == JFileChooser.APPROVE_OPTION) {
		ch.ethz.sg.cuttlefish.gui.Cuttlefish.currentDirectory = fc
				.getCurrentDirectory();
		System.out
				.println("Current directory: " + fc.getCurrentDirectory());
		networkFile = fc.getSelectedFile();
		cxfDBNetwork = new ExploreNetwork();
		cxfDBNetwork.connect(new CxfNetwork(networkFile));
		cxfDBNetwork.setNetworkLoaded(true);
	} else {
		System.out.println("Input cancelled by user");
	}

	return cxfDBNetwork;
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:24,代碼來源:NetworkInitializer.java

示例6: 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));
    }
}
 
開發者ID:veluria,項目名稱:NativeJFileChooser,代碼行數:18,代碼來源:NativeJFileChooser.java

示例7: getJFileChooser

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
/**
 * Creates and initialized a {@link JFileChooser} for selecting the export target
 * @return the {@link JFileChooser}
 */
protected JFileChooser getJFileChooser() {

	// --- Create and initialize the JFileChooser -------
	JFileChooser jFileChooser = new JFileChooser();
	List<FileNameExtensionFilter> filtersList = this.getFileNameExtensionFilters();
	for (FileNameExtensionFilter filter : filtersList) {
		jFileChooser.addChoosableFileFilter(filter);
	}
	jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	jFileChooser.setMultiSelectionEnabled(false);
	jFileChooser.setAcceptAllFileFilterUsed(false);

	File proposedFile = new File(this.getProposedFileName());
	jFileChooser.setSelectedFile(proposedFile);
	jFileChooser.setCurrentDirectory(proposedFile);

	return jFileChooser;
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:23,代碼來源:ProjectExportController.java

示例8: jl_Imagen_ContactsMouseClicked

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
private void jl_Imagen_ContactsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jl_Imagen_ContactsMouseClicked
    // TODO add your handling code here:
    jl_Imagen_Contacts.setText("");

    JFileChooser fc = new JFileChooser();
    FileFilter filtro = new FileNameExtensionFilter("Imagenes", "png", "jpg", "jpeg", "gif");
    fc.setFileFilter(filtro);

    File Archivo;
    int op = fc.showOpenDialog(this);

    if (op == JFileChooser.APPROVE_OPTION) {
        Archivo = fc.getSelectedFile();
        RutaImagen = Archivo.getPath();
        System.out.println(Archivo.getPath());
        Image Img = Toolkit.getDefaultToolkit().createImage(Archivo.getPath()).getScaledInstance(180, 229, 0);
        this.jl_Imagen_Contacts.setIcon(new ImageIcon(Img));
    }
}
 
開發者ID:alexycruz1,項目名稱:LP_Proyecto,代碼行數:20,代碼來源:Principal.java

示例9: initFileNetwork

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
private BrowsableNetwork initFileNetwork(String name, String extension)
		throws IOException {
	BrowsableNetwork network = null;

	JFileChooser fc = new FileChooser();
	fc.setDialogTitle("Select a " + name + " file");

	if (extension != null && !extension.isEmpty()) {
		fc.setFileFilter(new FileNameExtensionFilter("." + extension
				+ " files", extension));
	}

	int returnVal = fc.showOpenDialog(null);

	if (returnVal == JFileChooser.APPROVE_OPTION) {
		networkFile = fc.getSelectedFile();
		network = new BrowsableNetwork();
		network.load(networkFile);
		network.setNetworkLoaded(true);
	} else {
		System.out.println("Input cancelled by user");
	}

	return network;
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:26,代碼來源:NetworkInitializer.java

示例10: getFile

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
private static File getFile(Component parentComponent, File parentDirectory, FileNameExtensionFilter fileExtensionFilter, int fileSelectionMode, boolean saveDialog, String suggestedFileName) throws FileNotChosenException
{
	File file = null;
	
	if(parentDirectory != null)
		fc.setCurrentDirectory(parentDirectory);

	fc.setSelectedFile(suggestedFileName != null ? new File(suggestedFileName) : new File(""));			
	fc.setFileFilter(fileExtensionFilter);
	fc.setFileSelectionMode(fileSelectionMode);
	
	int returnVal;
	if(saveDialog)
		returnVal = fc.showSaveDialog(parentComponent);
	else
		returnVal = fc.showOpenDialog(parentComponent);
	
	if (returnVal == JFileChooser.APPROVE_OPTION) 
		file = fc.getSelectedFile();
	else
		throw new FileNotChosenException();
	
	return file;
}
 
開發者ID:ObsidianSuite,項目名稱:ObsidianSuite,代碼行數:25,代碼來源:FileChooser.java

示例11: openMenuActionPerformed

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
private void openMenuActionPerformed(java.awt.event.ActionEvent evt) {                                         
    FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
    openChooser.setFileFilter(filter);
    openChooser.showOpenDialog(saveBtn);
    if (openChooser.getSelectedFile() == null)
        return;
    String text = "";
    try {
        for (String line : Files.readAllLines(Paths.get(openChooser.getSelectedFile().getPath()))) {
            text += line + "\n";
        }
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
    filePaths.add(openChooser.getSelectedFile().getPath());
    javax.swing.JTextArea newTextArea = new javax.swing.JTextArea(text);
    newTextArea.setLineWrap(true);
    javax.swing.JScrollPane scroll = new javax.swing.JScrollPane(newTextArea);
    editTabs.addTab(openChooser.getSelectedFile().getName(), scroll);
}
 
開發者ID:GTextEditor,項目名稱:GTextEditor,代碼行數:22,代碼來源:Main.java

示例12: browseButtonActionPerformed

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
	FileChooser fc = new FileChooser();
	fc.setDialogTitle("Output to file...");
	fc.setFileFilter(new FileNameExtensionFilter(".tex files", "tex"));
	int returnVal = fc.showSaveDialog(networkPanel);				
	if (returnVal == JFileChooser.APPROVE_OPTION) {					
		tikzExporter.setOutputFile(fc.getSelectedFile());
		exportButton.setEnabled(true);
		String filePath = "";
		try {
			filePath = fc.getSelectedFile().getCanonicalPath();
		} catch (IOException e) {
			e.printStackTrace();
		}
		fileTextField.setText(filePath);
	}
	this.toFront();
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:19,代碼來源:TikzDialog.java

示例13: askFile

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
/**
 * Ask the user for a file to load or write to. Uses the AWT FileDialog on
 * macOS and the JFileChooser on other platforms. Makes sure the dialog is
 * displayed in the event dispatch thread.
 *
 * @param frame A Frame for which to display the dialog. Cannot be null.
 * @param message A message that will be displayed in the dialog.
 * @param defaultFile The default file name.
 * @param load Pass true if an existing file for reading should be selected.
 * Pass false if a new file for writing should be specified.
 * @param ext A file extension that is required when selecting a file name
 * for saving a file. Can be null.
 * @param filter filter used on Windows by the file chooser to filter out
 * files from the user's view.
 * @return A path to the file, including the file name.
 */
public static String askFile(final java.awt.Frame frame, final String message,
        final String defaultFile, final boolean load, final String ext,
        final FileNameExtensionFilter filter) {

    GUI gui = new GUI();
    gui.frame = frame;
    gui.message = message;
    gui.defaultFile = defaultFile;
    gui.load = load;
    gui.ext = ext;
    gui.filter = filter;

    // make sure we run in the event dispatch thread.
    SwingThreadUtils.invokeAndWait(gui);
    return gui.filePath;
}
 
開發者ID:berniejenny,項目名稱:MapAnalyst,代碼行數:33,代碼來源:FileUtils.java

示例14: saveProjectMenuItemActionPerformed

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
private void saveProjectMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveProjectMenuItemActionPerformed
        // ask for file path if the document has never been saved or if its
        // path is invalid.
        String ext = ika.mapanalyst.ApplicationInfo.getDocumentExtension();
        if (filePath == null || !new java.io.File(filePath).exists()) {
            filePath = FileUtils.askFile(this, "Save Project", 
                    exportFileName(ext), false, ext, 
                    new FileNameExtensionFilter("MapAnalyst", ext));
        }

        if (filePath == null) {
            return; // user canceled
        }
        // Don't move this to saveProject(). The path with the correct extension
        // has to be stored.
        filePath = ika.utils.FileUtils.forceFileNameExtension(filePath, ext);
        // the user canceled if filePath is null
        if (filePath != null) {
            saveProject(filePath);
            cleanDirty();
            String fileName = FileUtils.getFileNameWithoutExtension(filePath);
            setTitle(fileName + (Sys.isWindows() ? " - MapAnalyst" : ""));
            MainWindow.updateAllMenusOfAllWindows();
        }
}
 
開發者ID:berniejenny,項目名稱:MapAnalyst,代碼行數:26,代碼來源:MainWindow.java

示例15: getFileName

import javax.swing.filechooser.FileNameExtensionFilter; //導入依賴的package包/類
/**
 * Вызывает диалог выбора файла.
 *
 * @param parent Относительно чего показывать форму диалога.
 * @param title Заголовок диалогового окна.
 * @param description Описание фильтра, например "Файлы XML(*.xml)".
 * @param extension Фильтр по расширению файлов, например "xml".
 * @return Полное имя файла или null если не выбрали.
 */
public static String getFileName(Component parent, String title, String description,
    String extension) {
    final JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(Locales.getInstance().getLangCurrent());
    fileChooser.resetChoosableFileFilters();
    final FileNameExtensionFilter filter = new FileNameExtensionFilter(description, extension);
    fileChooser.setFileFilter(filter);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setDialogTitle(title);

    if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        if (fileChooser.getSelectedFile().exists()) {
            return fileChooser.getSelectedFile().getAbsolutePath();
        }
    }
    return null;
}
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:27,代碼來源:Uses.java


注:本文中的javax.swing.filechooser.FileNameExtensionFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。