List of utility methods to do JFileChooser
File[] | getFilesToOpen(File startDirectory, Component parent, String... filters) get Files To Open JFileChooser chooser = new JFileChooser(startDirectory); FileNameExtensionFilter filter = new FileNameExtensionFilter("Soubory " + toString(filters), filters); chooser.setFileFilter(filter); chooser.setMultiSelectionEnabled(true); int returnValue = chooser.showOpenDialog(parent); if (returnValue == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFiles(); return new File[0]; |
File | getFileToSave(String description, String extension, Component component) get File To Save JFileChooser fileChooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter(description, new String[] { extension }); fileChooser.setFileFilter(filter); int action = fileChooser.showSaveDialog(component); if (action == JFileChooser.APPROVE_OPTION) { if (fileChooser.getSelectedFile() != null) { File theFile = fileChooser.getSelectedFile(); if (!theFile.getAbsolutePath().toLowerCase().endsWith("." + extension)) { ... |
File | getFileWithExtension(JFileChooser c) Returns the selected file from a JFileChooser, including the extension from the file filter. File file = c.getSelectedFile(); if (c.getFileFilter() instanceof FileNameExtensionFilter) { String[] exts = ((FileNameExtensionFilter) c.getFileFilter()).getExtensions(); String nameLower = file.getName().toLowerCase(); for (String ext : exts) { if (nameLower.endsWith('.' + ext.toLowerCase())) { return file; file = new File(file.toString() + '.' + exts[0]); return file; |
JFileChooser | getFixedFileChooser(File file) Returns a file chooser that should not trip the bug with Java and Windows XP zip/rar folder feature. JFileChooser fileChooser = file != null ? new JFileChooser(file) : new JFileChooser(); fileChooser.putClientProperty("FileChooser.useShellFolder", Boolean.FALSE); return fileChooser; |
Icon | getIcon(File file) get Icon if (file == null) { return null; return basicChooser.getIcon(file); |
JFileChooser | getJFileChooser(String title, File initialDirectory, File initialFile, final FilenameFilter filter, int directoryMode) get J File Chooser JFileChooser fileChooser = new JFileChooser(); if (initialDirectory != null) { fileChooser.setCurrentDirectory(initialDirectory); if (initialFile != null) { fileChooser.setSelectedFile(initialFile); if (filter != null) { ... |
File | getLoadFilename(Component parent) Get a filename to load from. _fileChooser.setMultiSelectionEnabled(false); _fileChooser.setSelectedFile(new File("x")); _fileChooser.setSelectedFile(new File("")); int option = _fileChooser.showOpenDialog(parent); if (option == JFileChooser.APPROVE_OPTION) { File filename = _fileChooser.getSelectedFile(); if (filename.exists()) { return filename; ... |
File[] | getLoadFiles(String message, File openDefaultDirectory, String description, String... extensions) get Load Files java.awt.Frame frame = new java.awt.Frame(); frame.setTitle(message); final JFileChooser chooser = new JFileChooser(openDefaultDirectory); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); FileNameExtensionFilter filter = new FileNameExtensionFilter(description, extensions); chooser.setFileFilter(filter); final int returnVal = chooser.showOpenDialog(frame); ... |
JFileChooser | getNewFileChooser() get New File Chooser return getNewFileChooser(FILE_FILTER_EXCEL, FILE_FILTER_CSV);
|
File | getOpenFile(String defaultPath) Generic method to get a file using a JFileChooser File file = null; JFileChooser chooser = new JFileChooser(); if (defaultPath != null) { chooser.setCurrentDirectory(new File(defaultPath)); int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { defaultPath = chooser.getSelectedFile().getParentFile().getPath(); ... |