List of usage examples for javax.swing JFileChooser OPEN_DIALOG
int OPEN_DIALOG
To view the source code for javax.swing JFileChooser OPEN_DIALOG.
Click Source Link
JFileChooser
supports an "Open" file operation. From source file:savant.export.ExportPlugin.java
private void setupGUI(JPanel panel) { panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); //create padding gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 0;//w w w. j a v a2 s . c o m gbc.weighty = 0; gbc.gridx = 0; gbc.gridy = 0; JPanel fill1 = new JPanel(); fill1.setPreferredSize(new Dimension(10, 10)); panel.add(fill1, gbc); //create path chooser JLabel htmlLabel = new JLabel( "<html>Choose folder to save files.<br>An html index file will be created here.</html>"); gbc.gridwidth = 2; gbc.gridx = 1; gbc.gridy = 1; panel.add(htmlLabel, gbc); pf = new PathField(JFileChooser.OPEN_DIALOG, false, true); gbc.gridx = 1; gbc.gridy = 2; panel.add(pf, gbc); //create runExport button JButton runButton = new JButton("Run"); runButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { exportThread = new Thread("Export Plugin") { @Override public void run() { try { runTool(); } catch (InterruptedException ex) { //TODO: deal with exception? LOG.error("Export interrupted.", ex); } } }; exportThread.start(); //create progress dialog Object[] options = { "Cancel" }; progressPanel = new JOptionPane(" Running Export: 1"); progressPanel.setOptions(options); progressDialog = progressPanel.createDialog("Export in progress"); progressDialog.setVisible(true); if (progressPanel.getValue().equals("Cancel")) { exportCancelled = true; } } }); gbc.weightx = 0; gbc.gridwidth = 1; gbc.weightx = 0; gbc.weighty = 0; gbc.gridx = 1; gbc.gridy = 3; panel.add(runButton, gbc); //create output label outputLabel = new JLabel(); Font f = outputLabel.getFont(); outputLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD)); gbc.gridx = 2; gbc.gridy = 3; panel.add(outputLabel, gbc); //create padding JPanel fill2 = new JPanel(); fill2.setPreferredSize(new Dimension(10, 10)); gbc.weightx = 1.0; gbc.gridwidth = 1; gbc.gridx = 2; gbc.gridy = 3; panel.add(fill2, gbc); JPanel fill3 = new JPanel(); fill3.setPreferredSize(new Dimension(10, 10)); gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.gridwidth = 2; gbc.gridx = 0; gbc.gridy = 4; panel.add(fill3, gbc); }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Open or create a SQL statement file.//from w ww. j av a 2s . com */ private void openSQLFile() { JFileChooser fileMenu; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenSQLFile; int returnVal; chosenSQLFile = null; // Save current information, including SQL Statements saveConfig(); // Allow user to choose/create new file for SQL Statements fileMenu = new JFileChooser(new File(queryFilename)); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("QUERY")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileMenu.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenQueryFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileMenu.setFileFilter(defaultFileFilter); } else if (latestChosenQueryFileFilterDescription != null && latestChosenQueryFileFilterDescription.startsWith("All")) { fileMenu.setFileFilter(fileMenu.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileMenu.setFileFilter(preferredFileFilter); } fileMenu.setSelectedFile(new File(queryFilename)); fileMenu.setDialogTitle(Resources.getString("dlgSQLFileTitle")); fileMenu.setDialogType(JFileChooser.OPEN_DIALOG); fileMenu.setFileSelectionMode(JFileChooser.FILES_ONLY); fileMenu.setMultiSelectionEnabled(false); if (fileMenu.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { chosenSQLFile = fileMenu.getSelectedFile(); // Adjust file suffix if necessary final FileFilter fileFilter = fileMenu.getFileFilter(); if (fileFilter != null && fileFilter instanceof SuffixFileFilter && !fileMenu.getFileFilter().accept(chosenSQLFile)) { chosenSQLFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(chosenSQLFile); } if (!chosenSQLFile.exists()) { returnVal = JOptionPane.showConfirmDialog(this, Resources.getString("dlgNewSQLFileText", chosenSQLFile.getName()), Resources.getString("dlgNewSQLFileTitle"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (returnVal == JOptionPane.NO_OPTION) { querySelection.removeAllItems(); queryText.setText(""); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } else if (returnVal == JOptionPane.CANCEL_OPTION) { chosenSQLFile = null; } } else { setQueryFilename(chosenSQLFile.getAbsolutePath()); querySelection.removeAllItems(); queryText.setText(""); loadCombo(querySelection, queryFilename); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } } try { latestChosenQueryFileFilterDescription = fileMenu.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable); } if (chosenSQLFile != null) { setQueryFilename(chosenSQLFile.getAbsolutePath()); saveConfig(); } }
From source file:us.paulevans.basicxslt.BasicXSLTFrame.java
/** * Helper method that populates aTextField by presenting a file-open dialog * to the user.//from w ww. j ava2 s .c o m * @param aTextField */ public void populateTFFromFileDialog(JTextField aTextField) throws IOException { int returnVal; File file; Utils.getInstance().getFileChooser().setDialogType(JFileChooser.OPEN_DIALOG); returnVal = Utils.getInstance().getFileChooser().showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = Utils.getInstance().getFileChooser().getSelectedFile(); setLastFileChosen(file.getAbsolutePath()); aTextField.setText(file.getAbsolutePath()); } }
From source file:weka.knowledgeflow.steps.TimeSeriesForecasting.java
/** * Set the filename to load from.// w ww .j a va 2s .co m * * @param filename the filename to load from */ @FilePropertyMetadata(fileChooserDialogType = JFileChooser.OPEN_DIALOG, directoriesOnly = false) @ProgrammaticProperty @OptionMetadata(displayName = "File to load forecaster from", description = "File to load a forecaster from at runtime", displayOrder = 2) public void setFilename(File filename) { m_fileName = filename; }