List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:org.pgptool.gui.ui.tools.browsefs.ExistingFileChooserDialog.java
public String askUserForFile() { JFileChooser ofd = buildFileChooserDialog(); int result = ofd.showOpenDialog(optionalParent); if (result != JFileChooser.APPROVE_OPTION) { return handleFileWasChosen(null); }//from w w w . j a va2s . co m File retFile = ofd.getSelectedFile(); if (retFile == null) { return handleFileWasChosen(null); } String ret = retFile.getAbsolutePath(); ret = handleFileWasChosen(ret); configPairs.put(configPairNameToRemember, FilenameUtils.getFullPathNoEndSeparator(ret)); return ret; }
From source file:it.unibas.spicygui.controllo.file.ActionFileChooserSchema.java
public void actionPerformed(ActionEvent e) { executeInjection();/*from w w w . j av a 2 s .c om*/ JFileChooser chooser = vista.getFileChooserApriXSD(); File file; int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()); if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); xmlConfigurationPM.setSchemaPath(file.getAbsolutePath()); } }
From source file:org.pgptool.gui.ui.tools.browsefs.MultipleFilesChooserDialog.java
/** * Blocking call to browse for files/*from www . j av a 2 s. co m*/ * * @return null if nothing was chosen, or array of files chosen otherwise */ public File[] askUserForMultipleFiles() { JFileChooser ofd = buildFileChooserDialog(); int result = ofd.showOpenDialog(optionalParent); if (result != JFileChooser.APPROVE_OPTION) { handleFilesWereChosen(null); return null; } File[] retFile = ofd.getSelectedFiles(); if (retFile == null || retFile.length == 0) { handleFilesWereChosen(null); return null; } handleFilesWereChosen(retFile); configPairs.put(configPairNameToRemember, FilenameUtils.getFullPathNoEndSeparator(retFile[0].getAbsolutePath())); return retFile; }
From source file:cloud.gui.DistributionSelectionActionListener.java
@SuppressWarnings("static-access") @Override//from w ww . ja va2 s . c om public void actionPerformed(ActionEvent e) { String name = (String) gui.getDistributions().getSelectedItem(); if (DistributionName.EXPONENTIAL.getName().equals(name)) { gui.decorateExponentialDistribution(); } else if (DistributionName.UNIFORM.getName().equals(name)) { gui.decorateForUniformDistribution(); } else if (DistributionName.CONSTANT.getName().equals(name)) { gui.decorateForConstantDistribution(); } else if (DistributionName.CUSTOM.getName().equals(name)) { JFileChooser fileChooser = new JFileChooser(); int returnVal = fileChooser.showOpenDialog(gui); if (returnVal == fileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { List<String> lines = FileUtils.readLines(file); boolean result = validate(lines); if (!result) { gui.decorateForInValidDistribution(); logger.error("Invalid Distribution file " + file.getName()); } else { gui.decorateForCustomDistribution(lines); logger.info("File " + file.getName() + " is imported to generate the distribution from"); } } catch (IOException e1) { e1.printStackTrace(); } } else { gui.getDistributions().setSelectedIndex(0); gui.decorateForUniformDistribution(); } } }
From source file:sample.fa.ScriptRunnerApplication.java
private void loadScript(ActionEvent ae) { JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(scriptContents); if (jfc.getSelectedFile() != null) { loadScript(jfc.getSelectedFile()); }/*from w w w. jav a2 s. c om*/ }
From source file:Main.java
public void actionPerformed(ActionEvent e) { int retVal;/* www .jav a2 s. com*/ JFileChooser fc = new JFileChooser(); if (e.getActionCommand().equals("Open ...")) { fc.addChoosableFileFilter(new TextFilter()); retVal = fc.showOpenDialog(this); } else retVal = fc.showSaveDialog(this); if (retVal == JFileChooser.APPROVE_OPTION) System.out.println(fc.getSelectedFile().getName()); }
From source file:sample.fa.ScriptRunnerApplication.java
private void saveScript(ActionEvent ae) { JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(scriptContents); File f = jfc.getSelectedFile(); if (f != null) { try {//w w w .ja v a 2s . com Files.write(f.toPath(), scriptContents.getText().getBytes()); } catch (IOException ex) { JOptionPane.showMessageDialog(scriptContents, ex.getMessage(), "Error Saving Script", JOptionPane.ERROR_MESSAGE); } } }
From source file:task5.Histogram.java
private void getImage() { String userDir = System.getProperty("user.home"); JFileChooser fileChooser = new JFileChooser(userDir + "/Desktop"); int result = fileChooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try {/*from w w w.java 2 s. c o m*/ img = ImageIO.read(selectedFile); myframe = get_MYIMAGE(); } catch (IOException ex) { Logger.getLogger(MyImage.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.nubits.nubot.launch.toolkit.LaunchUI.java
private String askUser() { //Create Options for option dialog String path = ""; // Set cross-platform Java L&F (also called "Metal") try {/*from w w w . jav a 2 s .c om*/ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); final ImageIcon icon = new ImageIcon(local_path + "/" + ICON_PATH); //Ask the user to ask for scratch Object[] options = { "Import existing JSON option file", "Configure the bot from scratch" }; int n = JOptionPane.showOptionDialog(new JFrame(), "Chose one of the following options:", "NuBot UI Launcher", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, icon, //do not use a custom Icon options, //the titles of buttons options[0]); //default button title if (n == JOptionPane.YES_OPTION) { //Prompt user to chose a file. JFileChooser fileChooser = createFileChoser(); int result = fileChooser.showOpenDialog(new JFrame()); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); path = selectedFile.getAbsolutePath(); LOG.info("Option file selected : " + path); } else { LOG.info("Closing Launch UI utility."); System.exit(0); } } } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException e) { LOG.error(e.toString()); } return path; }
From source file:MessageDigestTest.java
public void loadFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { String name = chooser.getSelectedFile().getAbsolutePath(); computeDigest(loadBytes(name));//from ww w .ja va 2s . c o m } }