List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:MyViewChooser.java
public MyViewChooser() { super("File View Test Frame"); setSize(350, 200);//w w w. j ava 2s. c o m setDefaultCloseOperation(EXIT_ON_CLOSE); parent = this; Container c = getContentPane(); c.setLayout(new FlowLayout()); JButton openButton = new JButton("Open"); final JLabel statusbar = new JLabel("Output of your selection will go here"); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser chooser = new JFileChooser(); // Ok, set up our own file view for the chooser chooser.setFileView(new ThumbNailFileView(MyViewChooser.this)); int option = chooser.showOpenDialog(parent); if (option == JFileChooser.APPROVE_OPTION) { statusbar.setText("You chose " + chooser.getSelectedFile().getName()); } else { statusbar.setText("You cancelled."); } } }); c.add(openButton); c.add(statusbar); }
From source file:EscribirCorreo.java
private void subir1FieldMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_subir1FieldMousePressed // TODO add your handling code here: // Buscar archivo para subir JFileChooser subir = new JFileChooser(); int opcion = subir.showOpenDialog(null); if (opcion == JFileChooser.APPROVE_OPTION) { archivo = subir.getSelectedFile().getPath(); nombre = subir.getSelectedFile().getName(); subir1Field.setText(archivo); }//from ww w .j a v a 2 s .c om }
From source file:avoking.com.documentos.scheduler.startup.Main.java
public String getPathDocs(JFileChooser fc) { fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int opc = fc.showOpenDialog(null); if (opc == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f != null) { if (f.isDirectory()) return f.getAbsolutePath(); else/*w ww . j a v a2s. c o m*/ return f.getParentFile().getAbsolutePath(); } else { // JOptionPane.showMessageDialog(null, "Selecciona una ruta valida!!", "Directorio incorrecto", JOptionPane.WARNING_MESSAGE); return ""; } } else return ""; }
From source file:examples.gp.monalisa.gui.GeneticDrawingView.java
@Action public void chooseImage() throws IOException { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(".")); fc.showOpenDialog(mainPanel); File file = fc.getSelectedFile(); targetImage = ImageIO.read(file); targetImageLabel.setIcon(scaleToImageLabel(targetImage)); fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight()); }
From source file:gd.gui.GeneticDrawingView.java
@Action public void chooseImage() throws IOException { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(".")); fc.showOpenDialog(mainPanel); File file = fc.getSelectedFile(); targetImage = ImageIO.read(file); targetImageLabel.setIcon(scaleToImageLabel(targetImage)); fittestDrawingView.setSize(targetImage.getWidth(), targetImage.getHeight()); }
From source file:csv.to.sql.parser.mainMenu.java
private void btnOpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenFileActionPerformed // TODO add your handling code here: JFileChooser myFile = new JFileChooser(); myFile.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); myFile.showOpenDialog(this); this.selectedFile = myFile.getSelectedFile(); if (this.selectedFile.exists()) { this.fileSelected = true; this.lblFile.setText(this.selectedFile.getName()); this.btnOpenFile.setEnabled(false); this.btnParse.setEnabled(true); } else {/*from ww w . j a va 2s .c o m*/ JOptionPane.showInternalMessageDialog(this, "The file doesn't exists!"); } }
From source file:com.ibm.watson.WatsonVRTraining.util.images.PhotoCaptureFrame.java
PhotoCaptureFrame() { jp = new JPanel(); jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(jp); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); scrollPane.setPreferredSize(new Dimension(dim.width / 2 - 40, dim.height - 117)); JButton btn = new JButton("Upload Image"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(System.getenv("user.home")); fc.setFileFilter(new JPEGImageFileFilter()); int res = fc.showOpenDialog(null); // We have an image! try { if (res == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //SharedResources.sharedCache.getCapturedImageList().add(file); File tmpf_name = File.createTempFile("tmp", "." + FilenameUtils.getExtension(file.getName())); System.out.println("cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); new CommandsUtils().executeCommand("bash", "-c", "cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); }/* ww w .j ava2s .c om*/ } catch (Exception iOException) { } } }); ImageRemainingProcessingLabel = new JLabel("REMAINIG IMAGES:0"); ImageRemainingProcessingLabel.setHorizontalAlignment(SwingConstants.LEFT); ImageRemainingProcessingLabel.setFont(new Font("Arial", Font.BOLD, 13)); ImagebeingProcessedLabel = new JLabel(" PROCESSING IMAGES:0"); ImagebeingProcessedLabel.setHorizontalAlignment(SwingConstants.LEFT); ImagebeingProcessedLabel.setFont(new Font("Arial", Font.BOLD, 13)); appIDLabel = new JLabel("APP-ID:" + AppConstants.unique_app_id); appIDLabel.setHorizontalAlignment(SwingConstants.LEFT); appIDLabel.setFont(new Font("Arial", Font.BOLD, 13)); headerPanel = new JPanel(new FlowLayout()); headerPanel.add(ImageRemainingProcessingLabel); headerPanel.add(ImagebeingProcessedLabel); headerPanel.add(btn); headerPanel.add(appIDLabel); headerPanel.setSize(new Dimension(getWidth(), 10)); JPanel contentPane = new JPanel(); contentPane.add(headerPanel); contentPane.add(scrollPane); f = new JFrame("IBM Watson Visual Prediction Window"); f.setContentPane(contentPane); f.setSize(dim.width / 2 - 30, dim.height - 40); f.setLocation(dim.width / 2, 0); f.setResizable(false); f.setPreferredSize(new Dimension(dim.width / 2 - 30, dim.height - 60)); f.setVisible(true); }
From source file:com.github.cmisbox.ui.UI.java
public File getWatchFolder() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); chooser.showOpenDialog(null); return chooser.getSelectedFile(); }
From source file:techtonic.Exports.java
private void saveExportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveExportActionPerformed format = (jpg.isSelected()) ? "jpg" : "png"; JFileChooser jfc = new JFileChooser(); int returnValue = jfc.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = jfc.getSelectedFile(); String cv = selectedFile.getName(); try {// ww w .jav a2 s . com eWidth = Integer.parseInt(width.getText().trim()); } catch (NumberFormatException nfe) { width.requestFocus(); return; } try { eHeight = Integer.parseInt(height.getText().trim()); } catch (NumberFormatException nfe) { width.requestFocus(); return; } try { ChartUtilities.saveChartAsJPEG(new File(Techtonic.getDefaultDirectory(), cv + "." + format), Techtonic.getFreeChart(), eWidth, eHeight); Techtonic.seteHeight(eHeight); Techtonic.seteWidth(eWidth); Techtonic.setFileName(name); Techtonic.setFileFormat(format); Techtonic.getStatusBar().setForeground(Color.blue); Techtonic.getStatusBar().setText("File Exported"); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Problem exporting file"); Techtonic.getStatusBar().setForeground(Color.red); Techtonic.getStatusBar().setText("File not exported"); } this.dispose(); } else { } }
From source file:IHM.FenetreAjoutAffiche.java
private void btnAfficheActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAfficheActionPerformed JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("ouvrir une image"); int reponse = chooser.showOpenDialog(this); boolean etat; if (reponse == JFileChooser.APPROVE_OPTION) { InputStream input = null; f = chooser.getSelectedFile();/*from w ww .j av a2s . c o m*/ nomAffiche = f.getName(); nomF = f.getAbsolutePath(); txtNomPhoto.setText(nomAffiche); } }