List of utility methods to do JFileChooser
File | correctSelectedFileExtension(JFileChooser chooser) correct Selected File Extension File file = chooser.getSelectedFile(); if (file == null) { return null; String name = file.getName(); String newName = name; if (name.matches("\"[^\"]+\"")) { newName = name.substring(1, name.length() - 1); ... |
JFileChooser | createChooser(String lastPath, final boolean checkOverrideFile) create Chooser return new JFileChooser(lastPath) { private static final long serialVersionUID = 1L; @Override public void approveSelection() { File f = getSelectedFile(); if (f.exists() && checkOverrideFile) { int result = JOptionPane.showConfirmDialog(this, "\"" + f.getName() + "\" already exists. Do you want to overwrite it?", "Existing file", ... |
JFileChooser | createFileChooser(File presetFile, final String... postfixes) create File Chooser JFileChooser fc = new JFileChooser(); if (presetFile != null) fc.setSelectedFile(presetFile); fc.setAcceptAllFileFilterUsed(postfixes == null || postfixes.length == 0); if (postfixes == null) return fc; for (final String postfix : postfixes) { if (postfix == null) ... |
JFileChooser | createFileChooser(String initDir) create File Chooser JFileChooser fileChooser = new JFileChooser(new File(initDir)); fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.getName().endsWith(".adv.xml") || f.isDirectory(); @Override public String getDescription() { ... |
JFileChooser | createFileChooser(String title, File dir, String filter) create File Chooser return createFileChooser(title, dir, new String[] { filter }); |
JFileChooser | createJFileChooser(String name) Returns a new JFileChooser properly set up for Tetrad. if (name == null) { name = "Save"; JFileChooser chooser = new JFileChooser(); String sessionSaveLocation = Preferences.userRoot().get("fileSaveLocation", ""); chooser.setCurrentDirectory(new File(sessionSaveLocation)); chooser.resetChoosableFileFilters(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); ... |
JFileChooser | createJFileChooserWithExistenceChecking() create J File Chooser With Existence Checking return new JFileChooser() { public void approveSelection() { File[] files = selectedFiles(this); if (files.length == 0) { return; for (int i = 0; i < files.length; i++) { if (!files[i].exists() && !files[i].isFile()) { ... |
JFileChooser | createJFileChooserWithOverwritePrompting() create J File Chooser With Overwrite Prompting return new JFileChooser() { public void approveSelection() { if (selectedFiles(this).length != 1) { return; File selectedFile = selectedFiles(this)[0]; if (selectedFile.exists() && !selectedFile.isFile()) { return; ... |
File | createOpenFileChooser(String title, String dir, Component parent, FileFilter filter) Create and open a single file chooser. final JFileChooser fileChooser = new JFileChooser(dir); fileChooser.setDialogTitle(title); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); fileChooser.setMultiSelectionEnabled(false); fileChooser.setFileFilter(filter); final int approve = fileChooser.showOpenDialog(parent); if (approve == JFileChooser.APPROVE_OPTION) { ... |
JFileChooser | createReportFileChooser(String curDir, File defaultReportFile) create Report File Chooser JFileChooser fc = new JFileChooser(curDir); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { String filename = f.getName(); if (filename.endsWith(".html") || filename.endsWith(".htm") || filename.endsWith(".xhtml")) return true; return false; ... |