List of usage examples for javax.swing JFileChooser setDialogTitle
@BeanProperty(preferred = true, description = "The title of the JFileChooser dialog window.") public void setDialogTitle(String dialogTitle)
JFileChooser
window's title bar. From source file:Main.java
public static JFileChooser createFileChooser(String title, FileFilter filter, int mode, boolean multiSelectionEnabled, int dialogType) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(title); fileChooser.setFileFilter(filter);// ww w .j av a2s . co m fileChooser.setFileSelectionMode(mode); fileChooser.setDialogType(dialogType); fileChooser.setMultiSelectionEnabled(multiSelectionEnabled); fileChooser.setCurrentDirectory(getLastDirectory()); return fileChooser; }
From source file:Main.java
public static File chooseDir(Component parent, String title) { JFileChooser chooser = new JFileChooser(); // chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle(title); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setApproveButtonText("Select Dir"); return chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION ? chooser.getSelectedFile() : null; }
From source file:net.fabricmc.installer.installer.LocalVersionInstaller.java
public static void install(File mcDir, IInstallerProgress progress) throws Exception { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(Translator.getString("install.client.selectCustomJar")); fc.setFileFilter(new FileNameExtensionFilter("Jar Files", "jar")); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File inputFile = fc.getSelectedFile(); JarFile jarFile = new JarFile(inputFile); Attributes attributes = jarFile.getManifest().getMainAttributes(); String mcVersion = attributes.getValue("MinecraftVersion"); Optional<String> stringOptional = ClientInstaller.isValidInstallLocation(mcDir, mcVersion); jarFile.close();/*from www. j a v a 2s. c om*/ if (stringOptional.isPresent()) { throw new Exception(stringOptional.get()); } ClientInstaller.install(mcDir, mcVersion, progress, inputFile); } else { throw new Exception("Failed to find jar"); } }
From source file:net.fabricmc.installer.installer.LocalVersionInstaller.java
public static void installServer(File mcDir, IInstallerProgress progress) throws Exception { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(Translator.getString("install.client.selectCustomJar")); fc.setFileFilter(new FileNameExtensionFilter("Jar Files", "jar")); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File inputFile = fc.getSelectedFile(); JarFile jarFile = new JarFile(inputFile); Attributes attributes = jarFile.getManifest().getMainAttributes(); String fabricVersion = attributes.getValue("FabricVersion"); jarFile.close();//from www . j av a 2s .c o m File fabricJar = new File(mcDir, "fabric-" + fabricVersion + ".jar"); if (fabricJar.exists()) { fabricJar.delete(); } FileUtils.copyFile(inputFile, fabricJar); ServerInstaller.install(mcDir, fabricVersion, progress, fabricJar); } else { throw new Exception("Failed to find jar"); } }
From source file:Main.java
/** * Creates a new JFileChooser and returns the selected path's location. * @param title//from ww w . j ava2s . co m * @param openTo * @param chooseDirectory * @param filter * @return */ public static String getFilePath(String title, String openTo, boolean chooseDirectory, FileFilter filter) { String location = null; JFileChooser chooser = new JFileChooser(title); chooser.setCurrentDirectory(new File(openTo)); chooser.setFileFilter(filter); chooser.setDialogTitle("Open Cache"); if (chooseDirectory) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } else { chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); } chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(chooser) == JFileChooser.APPROVE_OPTION) { location = chooser.getSelectedFile().getAbsolutePath(); } return location; }
From source file:Main.java
/** * Displays a {@link JFileChooser} to select a directory. * * @param title The title of the dialog. * @param startDirectory The directory where the dialog is initialed opened. * @return The {@link File} selected, returns null if no directory was selected. *//* ww w . j av a 2 s . c o m*/ public static File chooseDirectory(String title, String startDirectory) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle(title); if (startDirectory != null && !startDirectory.trim().equals("")) { chooser.setCurrentDirectory(new File(startDirectory)); } int status = chooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } return null; }
From source file:Main.java
/** * Displays a {@link JFileChooser} to select a directory. * * @param title The title of the dialog. * @param startDirectory The directory where the dialog is initialed opened. * @return The {@link File} selected, returns null if no directory was selected. */// w w w. j a v a 2 s . c o m public static File chooseDirectory(String title, File startDirectory) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle(title); if (startDirectory != null) { chooser.setCurrentDirectory(startDirectory); } int status = chooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } return null; }
From source file:Main.java
/** * Displays a {@link JFileChooser} to select a file. * * @param title The title of the dialog. * @param startDirectory The directory where the dialog is initialed opened. * @param fileExtension File extension to filter each content of the opened * directories. Example ".xml".//ww w . j a v a 2 s .c o m * @param startFile The preselected file where the dialog is initialed opened. * @return The {@link File} object selected, returns null if no file was selected. */ public static File chooseFile(String title, String startDirectory, final String fileExtension, String startFile) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(title); if (fileExtension != null && !fileExtension.trim().equals("")) { FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() || pathname.getName().endsWith(fileExtension); } @Override public String getDescription() { return "(" + fileExtension + ")"; } }; chooser.setFileFilter(filter); } if (startDirectory != null && !startDirectory.trim().equals("")) { chooser.setCurrentDirectory(new File(startDirectory)); } if (startFile != null && !startFile.trim().equals("")) { chooser.setSelectedFile(new File(startFile)); } int status = chooser.showOpenDialog(null); if (status == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } return null; }
From source file:com.rpgsheet.xcom.PimpMyXcom.java
private static void openXcomPathDialog(Properties appProperties) { // display the box to the user JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("PimpMyXcom - Where is X-COM?"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int retCode = fileChooser.showOpenDialog(null); // if the user cancelled the dialog, there is nothing we can do if (retCode == JFileChooser.CANCEL_OPTION) { log.error("User cancel while attempting to locate X-COM."); return;//from w ww . j a va 2 s . co m } // if there was an error, there is nothing we can do if (retCode == JFileChooser.ERROR_OPTION) { log.error("Error while attempting to locate X-COM: {}", JFileChooser.ERROR_OPTION); return; } // if the user chose a directory, then we have some work to do String xcomPath = fileChooser.getSelectedFile().getAbsolutePath(); File xcomDir = new File(xcomPath); if (containsXcom(xcomDir)) { // store the path to xcom in the application properties appProperties.setProperty("xcom.path", xcomPath); // write the updated application properties to disk try { saveApplicationProperties(appProperties); } catch (IOException e) { log.error("Unable to store X-COM path in application properties.", e); return; } } // if we were unable to find X-COM else { log.error("User provided location did not contain X-COM."); return; } }
From source file:Main.java
public static String browseForFile(Window owner, String file, int selectionMode, String title, FileFilter filter) {//from ww w.java 2 s . c om final String curDir = System.getProperty("user.dir"); JFileChooser chooser = new JFileChooser(curDir); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileSelectionMode(selectionMode); chooser.setApproveButtonText("Select"); chooser.setApproveButtonMnemonic('s'); chooser.setDialogTitle(title); if (filter != null) chooser.setFileFilter(filter); if (file != null && !file.isEmpty()) { File curFile = new File(file); chooser.setCurrentDirectory(curFile.getAbsoluteFile().getParentFile()); if (curFile.isDirectory()) { try { chooser.setSelectedFile(curFile.getCanonicalFile()); } catch (IOException ex) { } } else { chooser.setSelectedFile(curFile); } } if (chooser.showOpenDialog(owner) == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().getPath(); try { path = new File(path).getCanonicalPath(); } catch (IOException e) { } // make path relative if possible if (path.startsWith(curDir)) { path = "." + path.substring(curDir.length()); } return path; } return null; }