本文整理汇总了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.");
}
}
示例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));
}
示例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);
}
}
}
示例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;
}
}
示例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;
}
示例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));
}
}
示例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;
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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();
}
}
示例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;
}