List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:com.egangotri.transliteratorAsSwing.TransliteratorJFrame.java
public void chooseFile(JTextArea jta) { JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text"); chooser.setFileFilter(filter);/* w ww .ja v a 2 s.com*/ int option = chooser.showOpenDialog(this); if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { Log.info("You chose to open this file: " + chooser.getSelectedFile().getPath()); String path = chooser.getSelectedFile().getPath(); FileIO.readFile(new File(path), jta); } } }
From source file:com.adito.upgrade.GUIUpgrader.java
public GUIUpgrader() { super(new BorderLayout()); JPanel info = new JPanel(new BorderLayout(2, 2)); // info.setBackground(Color.white); // info.setForeground(Color.black); // info.setOpaque(true); info.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); JLabel l = new JLabel("<html><p>This utility upgrades configuration from " + "one version 0.1.16 installation to another " + "0.2.5+ installation. You may choose which resources you " + "wish to be copied. If resources with the same name already " + "exist they will be left as is."); l.setIcon(new ImageIcon(GUIUpgrader.class.getResource("upgrader-48x48.png"))); info.add(l, BorderLayout.CENTER); info.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH); mainPanel = new JPanel(new BorderLayout()); add(info, BorderLayout.NORTH); add(mainPanel, BorderLayout.CENTER); // Installations panel JPanel installations = new JPanel(new GridBagLayout()); installations.setBorder(BorderFactory.createTitledBorder("Installations")); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.WEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(2, 2, 2, 2); gbc.weightx = 2.0;//w w w. j a v a 2s . c o m UIUtil.jGridBagAdd(installations, new JLabel("Source"), gbc, GridBagConstraints.REMAINDER); gbc.weightx = 1.0; source = new JTextField(); source.getDocument().addDocumentListener(this); UIUtil.jGridBagAdd(installations, source, gbc, GridBagConstraints.RELATIVE); browseSource = new JButton("Browse"); browseSource.setMnemonic('b'); browseSource.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(source.getText()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Select source installation directory (0.16.1)"); if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) { source.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); gbc.weightx = 0.0; UIUtil.jGridBagAdd(installations, browseSource, gbc, GridBagConstraints.REMAINDER); gbc.weightx = 2.0; UIUtil.jGridBagAdd(installations, new JLabel("Target"), gbc, GridBagConstraints.REMAINDER); gbc.weightx = 1.0; target = new JTextField(System.getProperty("user.dir")); target.getDocument().addDocumentListener(this); UIUtil.jGridBagAdd(installations, target, gbc, GridBagConstraints.RELATIVE); browseTarget = new JButton("Browse"); browseTarget.setMnemonic('r'); browseTarget.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(target.getText()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Select target installation directory (0.2.5+)"); if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) { target.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); gbc.weightx = 0.0; UIUtil.jGridBagAdd(installations, browseTarget, gbc, GridBagConstraints.REMAINDER); mainPanel.add(installations, BorderLayout.NORTH); // Upgrade selection upgradeSelectionPanel = new JPanel(); upgradeSelectionPanel.setBorder(BorderFactory.createTitledBorder("Upgrades")); upgradeSelectionPanel.setLayout(new BoxLayout(upgradeSelectionPanel, BoxLayout.Y_AXIS)); mainPanel.add(upgradeSelectionPanel, BorderLayout.CENTER); }
From source file:com.biosis.biosislite.vistas.inventario.MantenimientoFactura.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: JFileChooser fc = new JFileChooser(); int respuesta = fc.showOpenDialog(this); if (respuesta == JFileChooser.APPROVE_OPTION) { File archivoElegido = fc.getSelectedFile(); facturaField.setText(archivoElegido.getAbsolutePath()); // fotolbl.setIcon(new ImageIcon("C:/Users/Documentos/Desktop/HS/" + fotosField.getText())); ImageIcon fot = new ImageIcon(facturaField.getText()); Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lblFactura.getWidth(), lblFactura.getHeight(), Image.SCALE_DEFAULT)); lblFactura.setIcon(icono);// w ww.ja va2 s. co m } }
From source file:com.stanley.captioner.MainFrame.java
private void outputDirectoryButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_outputDirectoryButtonActionPerformed {//GEN-HEADEREND:event_outputDirectoryButtonActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (lastOutputDirectory != null) { fileChooser.setCurrentDirectory(lastOutputDirectory); }/*from w w w . j a va 2 s . com*/ int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { lastOutputDirectory = fileChooser.getCurrentDirectory(); File file = fileChooser.getSelectedFile(); outputDirectoryField.setText(file.getAbsolutePath()); if (videoTable.getRowCount() > 0 && outputDirectoryField.getText().length() > 0) { convertButton.setEnabled(true); } } }
From source file:carolina.pegaLatLong.LatLong.java
private void btnCarregaTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCarregaTxtActionPerformed // TODO add your handling code here JFileChooser escolhe = new JFileChooser(); // escolhe.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // escolhe.setAcceptAllFileFilterUsed(false); int i = escolhe.showOpenDialog(null); if (i != 1) { String caminho = escolhe.getSelectedFile().getPath(); edtTxt.setText(escolhe.getSelectedFile().getName()); btnCarregaTxt.setEnabled(false); new Thread(new Runnable() { @Override//from w w w . j a va 2s . co m public void run() { try { buscaLtLong(carregaRetorna(caminho)); } catch (IOException ex) { Logger.getLogger(LatLong.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(LatLong.class.getName()).log(Level.SEVERE, null, ex); } } }).start(); } }
From source file:com.mirth.connect.client.ui.MessageImportDialog.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }//from www .j ava 2 s. c o m } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } fileTextField.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:de.codesourcery.jasm16.ide.ui.views.EmulationOptionsView.java
public EmulationOptionsView() { emulatorPanel.setLayout(new GridBagLayout()); GridBagConstraints cnstrs = constraints(0, 0, false, false, GridBagConstraints.NONE); emulatorPanel.add(new JLabel("Emulation speed"), cnstrs); cnstrs = constraints(1, 0, true, true, GridBagConstraints.NONE); cnstrs.anchor = GridBagConstraints.WEST; emulatorPanel.setBorder(BorderFactory.createTitledBorder("General options")); speedBox.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(javax.swing.JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final java.awt.Component result = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);/* ww w.j a va 2s. c o m*/ if (value != null) { switch ((EmulationSpeed) value) { case MAX_SPEED: setText("Max."); break; case REAL_SPEED: setText("100 kHz"); break; default: setText(value.toString()); break; } } return result; }; }); emulatorPanel.add(speedBox, cnstrs); // disk drive panel selectedFileField.setColumns(25); diskDrivePanel.setLayout(new GridBagLayout()); cnstrs = constraints(0, 0, false, true, GridBagConstraints.NONE); cnstrs.anchor = GridBagConstraints.CENTER; diskDrivePanel.setBorder(BorderFactory.createTitledBorder("Disk drive")); diskDrivePanel.add(selectedFileField, cnstrs); cnstrs = constraints(1, 0, false, true, GridBagConstraints.NONE); cnstrs.anchor = GridBagConstraints.CENTER; diskDrivePanel.add(fileChooserButton, cnstrs); fileChooserButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JFileChooser chooser; if (getSelectedFile() != null) { chooser = new JFileChooser(getSelectedFile().getParentFile()); } else { chooser = new JFileChooser(); } final int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION && chooser.getSelectedFile().isFile()) { selectedFileField.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); cnstrs = constraints(2, 0, false, true, GridBagConstraints.NONE); cnstrs.anchor = GridBagConstraints.CENTER; diskDrivePanel.add(writeProtected, cnstrs); }
From source file:InterfaceModule.JRobert.java
private File loadFile() { JFileChooser chooser = new JFileChooser(System.getProperty("user.dir") + "/saves/"); FileNameExtensionFilter filter = new FileNameExtensionFilter("TXT file", "txt"); chooser.setFileFilter(filter);//from w ww . j av a 2 s. com int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } else return null; }
From source file:au.org.ala.delta.intkey.ui.DefineButtonDialog.java
@Action public void DefineButtonDialog_Browse() { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter(fileFilterDescription, new String[] { "bmp", "png" }); chooser.setFileFilter(filter);/*from w w w. j a va 2 s . c om*/ int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); _txtFldFileName.setText(selectedFile.getAbsolutePath()); } }
From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java
private void show_open_hamql_dialog() { FileFilter filter = createFilter(); JFileChooser jf = new JFileChooser("conf/query/"); jf.setFileFilter(filter);//from w ww . j a va 2 s . c o m jf.setDialogTitle("HamQL (SpinQL) ?J"); int returnVal = jf.showOpenDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) return; File f = jf.getSelectedFile(); try { FileReader reader = new FileReader(f); BufferedReader br = new BufferedReader(reader); StringBuilder buf = new StringBuilder(); String tmp = null; while ((tmp = br.readLine()) != null) { buf.append(tmp + "\n"); } br.close(); reader.close(); getJTextArea().setText(buf.toString()); } catch (Exception e) { e.printStackTrace(); } }