// $$ modif from Oury private static JFileChooser getFileChooser(Component owner, int mode) { JFileChooser chooser = null; String last = /*Jext*/ AbstractEditorPanel.getProperty("lastdir." + mode); if (last == null) last = /*Jext*/ AbstractEditorPanel.getHomeDirectory(); if (owner instanceof AbstractEditorPanel) { chooser = ((/*Jext*/ AbstractEditorPanel) owner).getFileChooser(mode); if ( /*Jext*/ AbstractEditorPanel.getBooleanProperty("editor.dirDefaultDialog") && mode != SCRIPT) { String file = ((AbstractEditorPanel) owner) // $$ from Seb [[ // .getTextArea() // $$ from Seb ]] .getCurrentFile(); if (file != null) chooser.setCurrentDirectory(new File(file)); } else chooser.setCurrentDirectory(new File(last)); } else { chooser = new JFileChooser(last); if (mode == SAVE) chooser.setDialogType(JFileChooser.SAVE_DIALOG); else chooser.setDialogType(JFileChooser.OPEN_DIALOG); } chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileHidingEnabled(true); return chooser; }
public MainForm() { alfa.setValue(1); beta.setValue(1); gamma.setValue(1); loadDatabase.addActionListener( e -> { fileChooser.setCurrentDirectory(new File(database.getText())); int returnVal = fileChooser.showOpenDialog(panel1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); database.setText(file.getPath()); } }); loadKeyword.addActionListener( e -> { fileChooser.setCurrentDirectory(new File(keywords.getText())); int returnVal = fileChooser.showOpenDialog(panel1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); keywords.setText(file.getPath()); } }); search.addActionListener( e -> { isKeywordsEnabled = keywordsEnabled.getSelectedIndex() != 0; DatabaseCollection.clear(); if (isKeywordsEnabled) { new KeywordParser(keywords.getText()).parse(); } new DocumentParser(database.getText()).parse(); Method method1 = Method.valueOf((String) MainForm.this.method.getSelectedItem()); Document query1 = new Document(MainForm.this.query.getText(), "", false); showResults(method1, query1); }); oznacz.addActionListener( e -> { for (Result result : results.getSelectedValuesList()) { result.setMarkedAsGood(!result.isMarkedAsGood()); } results.repaint(); }); newQuestion.addActionListener( e -> { ResultModel model = (ResultModel) results.getModel(); Document query1 = model.getQuery(); calculateRelevance( model.getResultList(), query1, (Integer) alfa.getValue(), (Integer) beta.getValue(), (Integer) gamma.getValue()); queryHelp.setText(query1.getQueryText()); Method method1 = Method.valueOf((String) MainForm.this.method.getSelectedItem()); showResults(method1, query1); }); }
private static void assertChooser() { if (fc == null) { fc = new JFileChooser(); Box ab = new Box(BoxLayout.Y_AXIS); ab.add(afap = new AudioFormatAccessoryPanel("Sample format")); ab.add(sap = new SaveAccessoryPanel(null)); fc.setAccessory(ab); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileFilter( new FileFilter() { public boolean accept(File f) { return f.isDirectory() && !f.equals(Zoeos.getZoeosLocalDir()); } public String getDescription() { return "Directories"; } }); fc.setAcceptAllFileFilterUsed(false); } try { fc.setCurrentDirectory(new File(ZPREF_lastDir.getValue())); } catch (Exception e) { } }
public void initGame() { String cfgname = null; if (isApplet()) { cfgname = getParameter("configfile"); } else { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); chooser.setDialogTitle("Choose a config file"); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { cfgname = chooser.getSelectedFile().getAbsolutePath(); } else { System.exit(0); } // XXX read this as resource! // cfgname = "mygeneratedgame.appconfig"; } gamecfg = new AppConfig("Game parameters", this, cfgname); gamecfg.loadFromFile(); gamecfg.defineFields("gp_", "", "", ""); gamecfg.saveToObject(); initMotionPars(); // unpause and copy settingswhen config window is closed gamecfg.setListener( new ActionListener() { public void actionPerformed(ActionEvent e) { start(); requestGameFocus(); initMotionPars(); } }); defineMedia("simplegeneratedgame.tbl"); setFrameRate(35, 1); }
public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(exaktFrame.getLastCorpusPath()); fileChooser.setDialogTitle("Open COMA Corpus file"); fileChooser.setFileFilter( new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { String name = f.getAbsolutePath(); return (f.isDirectory() || name.substring(Math.max(0, name.length() - 3)).equalsIgnoreCase("XML") || name.substring(Math.max(0, name.length() - 4)).equalsIgnoreCase("COMA")); } public String getDescription() { return "XML files, CoMa files (*.xml, *.coma)"; } }); int retValue = fileChooser.showOpenDialog(exaktFrame); if (retValue == JFileChooser.APPROVE_OPTION) { final File file = fileChooser.getSelectedFile(); exaktFrame.doOpen(file); exaktFrame.setLastCorpusPath(file); } }
protected void selectFile() { ResourceManager rm = ResourceManager.all(FilePropertyEditor.class); JFileChooser chooser = UserPreferences.getDefaultDirectoryChooser(); chooser.setDialogTitle(rm.getString("DirectoryPropertyEditor.dialogTitle")); chooser.setApproveButtonText(rm.getString("DirectoryPropertyEditor.approveButtonText")); chooser.setApproveButtonMnemonic(rm.getChar("DirectoryPropertyEditor.approveButtonMnemonic")); File oldFile = (File) getValue(); if (oldFile != null && oldFile.isDirectory()) { try { chooser.setCurrentDirectory(oldFile.getCanonicalFile()); } catch (IOException e) { e.printStackTrace(); } } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(editor)) { File newFile = chooser.getSelectedFile(); String text = newFile.getAbsolutePath(); textfield.setText(text); firePropertyChange(oldFile, newFile); } }
private void changeDirectory(File dir) { JFileChooser fc = getFileChooser(); // Traverse shortcuts on Windows if (dir != null && FilePane.usesShellFolder(fc)) { try { ShellFolder shellFolder = ShellFolder.getShellFolder(dir); if (shellFolder.isLink()) { File linkedTo = shellFolder.getLinkLocation(); // If linkedTo is null we try to use dir if (linkedTo != null) { if (fc.isTraversable(linkedTo)) { dir = linkedTo; } else { return; } } else { dir = shellFolder; } } } catch (FileNotFoundException ex) { return; } } fc.setCurrentDirectory(dir); if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES && fc.getFileSystemView().isFileSystem(dir)) { setFileName(dir.getAbsolutePath()); } }
private void jMenuItemImportActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemImportActionPerformed JFileChooser jfc = new JFileChooser(); jfc.setMultiSelectionEnabled(true); if (lastPath != null) { jfc.setCurrentDirectory(lastPath); } int fileDialogReturnVal = jfc.showOpenDialog(this); // now select the file if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) { // add code here to allow selection of a document class DocumentClassDialog d = DocumentClassDialog.showClassDialog(this, this.theProject); DocumentClass selectedClass = d.getSelectedDocumentClass(); File[] selected = jfc.getSelectedFiles(); for (int i = 0; i < selected.length; i++) { theProject.addNewDocument(selected[i], 1.0f, selected[i].toString(), selectedClass); } docFrameTableModel.fireTableDataChanged(); lastPath = new File(jfc.getSelectedFile().getPath()); } } // GEN-LAST:event_jMenuItemImportActionPerformed
private void setStartingDirectory() { File startingDirectoryFile = new File(ISAcreatorProperties.getProperty("isacreator.mappingFileLocations")); if (!startingDirectoryFile.getAbsolutePath().isEmpty() && startingDirectoryFile.exists()) { fileChooser.setCurrentDirectory(startingDirectoryFile); } }
private void findPresentation() { JFileChooser fileChooser = new JFileChooser(); if (lastDirectory_ != null) fileChooser.setCurrentDirectory(lastDirectory_); // if (imc.lecturnity.converter.ConverterWizard.USE_CUSTOM_COLORS) if (USE_CUSTOM_COLORS) fileChooser.setBackground(Wizard.BG_COLOR); LecturnityFileFilter lff = new LecturnityFileFilter(); fileChooser.addChoosableFileFilter(lff); LpdFileFilter lpf = new LpdFileFilter(); fileChooser.addChoosableFileFilter(lpf); EPresentationFileFilter eff = new EPresentationFileFilter(); fileChooser.addChoosableFileFilter(eff); AofFileFilter aff = new AofFileFilter(); fileChooser.addChoosableFileFilter(aff); fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.setFileFilter(lff); Dimension fcSize = fileChooser.getPreferredSize(); fileChooser.setPreferredSize(new Dimension(fcSize.width + 100, fcSize.height + 50)); int action = fileChooser.showOpenDialog(this); lastDirectory_ = fileChooser.getCurrentDirectory(); if (action == fileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); presentationFileField_.setText(selectedFile.getAbsolutePath()); } }
/** * Actions-handling method. * * @param e The event. */ public void actionPerformed(ActionEvent e) { // Prepares the file chooser JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(idata.getInstallPath())); fc.setMultiSelectionEnabled(false); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); // fc.setCurrentDirectory(new File(".")); // Shows it try { if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // We handle the xml data writing File file = fc.getSelectedFile(); FileOutputStream out = new FileOutputStream(file); BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120); parent.writeXMLTree(idata.xmlData, outBuff); outBuff.flush(); outBuff.close(); autoButton.setEnabled(false); } } catch (Exception err) { err.printStackTrace(); JOptionPane.showMessageDialog( this, err.toString(), parent.langpack.getString("installer.error"), JOptionPane.ERROR_MESSAGE); } }
@Override public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); TypeFileFilter fileFilter = new TypeFileFilter("db"); fileChooser.setFileFilter(fileFilter); int result = fileChooser.showOpenDialog(_parent); }
private void showOpenFileDialog() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fileChooser.showSaveDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); txtHello.setText(selectedFile.getAbsolutePath()); } }
public Path dateiAuswählen(Path neuesLaufwerk) { JFileChooser fc1 = new JFileChooser(); fc1.setDialogTitle("SyncOrdner auswählen"); fc1.setCurrentDirectory(neuesLaufwerk.toFile()); fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) return fc1.getSelectedFile().toPath(); else return null; }
private File openFile(String title) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images (*.jpg, *.png, *.gif)", "jpg", "png", "gif"); chooser.setFileFilter(filter); chooser.setCurrentDirectory(openPath); int ret = chooser.showDialog(this, title); if (ret == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile(); return null; }
void doEditFilename() { // create the file open dialog final JFileChooser jf = new JFileChooser(); // cancel multiple selections jf.setMultiSelectionEnabled(false); // set the start directory if (_lastDirectory != null) { jf.setCurrentDirectory(new File(_lastDirectory)); } else { String val = ""; // see if we have an old directory to retrieve val = Application.getThisProperty("RANGE_Directory"); // give it a default value, if we have to if (val == null) val = ""; // try to get the import directory jf.setCurrentDirectory(new File(val)); } // open the dialog final int state = jf.showOpenDialog(null); // do we have a valid file? if (state == JFileChooser.APPROVE_OPTION) { // retrieve the filename final File theFile = jf.getSelectedFile(); _theFilename = theFile.getPath(); // retrieve the directory name _lastDirectory = theFile.getParent(); // trigger a refresh refreshForm(); } else if (state == JFileChooser.CANCEL_OPTION) { _theFilename = null; } }
private String getFileName(String title, String okButton, String currentDirectory) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(title); fileChooser.setApproveButtonText(okButton); fileChooser.setCurrentDirectory(new File(currentDirectory)); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); return selectedFile.getAbsolutePath(); } return null; }
private void downloadDirectoryButtonActionPerformed(ActionEvent evt) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(Groovesquid.getConfig().getDownloadDirectory())); chooser.setDialogTitle(I18n.getLocaleString("SELECT_DOWNLOAD_DIRECTORY")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String downloadDirectory = chooser.getSelectedFile().getPath(); Groovesquid.getConfig().setDownloadDirectory(downloadDirectory); downloadDirectoryTextField.setText(downloadDirectory); } }
/* * This function just finds and loads the file */ private boolean loadFile() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Load File"); // Choose only files, not directories fc.setFileSelectionMode(JFileChooser.FILES_ONLY); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Now open chooser int result = fc.showOpenDialog(this); if (result == JFileChooser.CANCEL_OPTION) { // return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("LOAD1")) { UpLoadFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD2")) { UpLoadFile.filePath2.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD3")) { VisualizationInput.originalFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD4")) { VisualizationInput.DWDVecFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD5")) { VisualizationInput.DWDOutputFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD6")) { UpLoadMAGEMLFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD7")) { UpLoadMAGEMLFile.filePath2.setText(textFile); } // Get the absolute path for the file being opened filePath = fFile.getAbsolutePath(); if (filePath == null) { // fTextField.setText (filePath); return false; } } else { return false; } return true; } /*End of loadFile*/
/** * Use a JFileChooser in Save mode to select files to open. Use a filter for FileFilter subclass * to select for "*.java" files. If a file is selected, then this file will be used as final * output */ boolean saveFile() { File file = null; JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("SAVE")) { UpLoadFile.outputfile.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVE2")) { UpLoadMAGEMLFile.outputfile1.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVE3")) { UpLoadMAGEMLFile.outputfile2.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVEJPAG")) { JPEGFileName = textFile; // System.out.println ("JPG filename OpenFileDir= " +JPEGFileName); File fFile = new File(JPEGFileName); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog( null, "Overwrite existing file " + JPEGFileName + " ??", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) { /* go back to reload the file*/ return false; } } SetUpPlotWindow.saveComponentAsJPEG(SetUpPlotWindow.content, JPEGFileName); } return true; } else { return false; } } // saveFile
private void showOpenFileDialog1() { JFileChooser fileChooser1 = new JFileChooser(); fileChooser1.setCurrentDirectory(new File(System.getProperty("user.home"))); fileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser1.addChoosableFileFilter( new FileNameExtensionFilter("Microsoft Excel Documents", "xlsx", ".xls")); fileChooser1.setAcceptAllFileFilterUsed(true); int result1 = fileChooser1.showSaveDialog(this); if (result1 == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser1.getSelectedFile(); textField_1.setText(selectedFile.getAbsolutePath()); } }
/** Loads a file and computes its message digest. */ public void loadFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { try { String name = chooser.getSelectedFile().getAbsolutePath(); computeDigest(loadBytes(name)); } catch (IOException e) { JOptionPane.showMessageDialog(null, e); } } }
private void selectFolder() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(textFolder.getText())); fileChooser.setDialogTitle(CAPTION_SELECT_FOLDER); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setApproveButtonText("Select"); fileChooser.setApproveButtonToolTipText(TOOL_TIP_SELECT_FOLDER); if (fileChooser.showOpenDialog(FileTransferServer.this) == JFileChooser.APPROVE_OPTION) { // Get the selected file String path = fileChooser.getSelectedFile().getPath() + "\\"; textFolder.setText(path); } }
public void actionPerformed(ActionEvent e) { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("C:\\Program Files (x86)\\Tango04\\Dashboards\\Web")); chooser.setDialogTitle("Browse..."); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { textArea.setText(""); new Exportator().startExporting(chooser.getSelectedFile().getPath(), textArea); } else { textArea.setText("No Selection"); } }
public JFileChooser createFileChooser() { // create a filechooser JFileChooser fc = new JFileChooser(); if (getSwingSet2() != null && getSwingSet2().isDragEnabled()) { fc.setDragEnabled(true); } // set the current directory to be the images directory File swingFile = new File("resources/images/About.jpg"); if (swingFile.exists()) { fc.setCurrentDirectory(swingFile); fc.setSelectedFile(swingFile); } return fc; }
public static Map[] showOpenMapDialog(final JFrame owner) throws IOException { final JFileChooser ch = new JFileChooser(); if (config.getFile("mapLastOpenDir") != null) { ch.setCurrentDirectory(config.getFile("mapLastOpenDir")); } ch.setDialogType(JFileChooser.OPEN_DIALOG); ch.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (ch.showOpenDialog(MainFrame.getInstance()) != JFileChooser.APPROVE_OPTION) { return null; } final File dir = ch.getSelectedFile(); config.set("mapLastOpenDir", dir); final String[] maps = dir.list(FILTER_TILES); for (int i = 0; i < maps.length; ++i) { maps[i] = maps[i].substring(0, maps[i].length() - MapIO.EXT_TILE.length()); } final JDialog dialog = new JDialog(owner, Lang.getMsg("gui.chooser")); dialog.setModal(true); dialog.setLocationRelativeTo(null); dialog.setLayout(new BorderLayout()); final JList list = new JList(maps); final JButton btn = new JButton(Lang.getMsg("gui.chooser.Ok")); btn.addActionListener( new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { if (list.getSelectedValue() != null) { dialog.setVisible(false); } } }); dialog.add(new JScrollPane(list), BorderLayout.CENTER); dialog.add(btn, BorderLayout.SOUTH); dialog.pack(); dialog.setVisible(true); dialog.dispose(); Map[] loadedMaps = new Map[list.getSelectedIndices().length]; for (int i = 0; i < list.getSelectedIndices().length; i++) { loadedMaps[i] = MapIO.loadMap(dir.getPath(), (String) list.getSelectedValues()[i]); } return loadedMaps; }
public SwingWorkerFrame() { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); textArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS); add(new JScrollPane(textArea)); statusLine = new JLabel(" "); add(statusLine, BorderLayout.SOUTH); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); openItem = new JMenuItem("Open"); menu.add(openItem); openItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // show file chooser dialog int result = chooser.showOpenDialog(null); // if file selected, set it as icon of the label if (result == JFileChooser.APPROVE_OPTION) { textArea.setText(""); openItem.setEnabled(false); textReader = new TextReader(chooser.getSelectedFile()); textReader.execute(); cancelItem.setEnabled(true); } } }); cancelItem = new JMenuItem("Cancel"); menu.add(cancelItem); cancelItem.setEnabled(false); cancelItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { textReader.cancel(true); } }); pack(); }
private void backup_folder_buttonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_backup_folder_buttonActionPerformed try { JFileChooser sel = new JFileChooser(); sel.setCurrentDirectory(new java.io.File(".")); sel.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); sel.setAcceptAllFileFilterUsed(false); if (sel.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File selFile = sel.getSelectedFile(); Backup_textfield.setText(selFile.getCanonicalPath()); path_save_chat = selFile.getCanonicalPath() + "\\"; } else { // do nothing } } catch (IOException ex) { Logger.getLogger(Options.class.getName()).log(Level.SEVERE, null, ex); } } // GEN-LAST:event_backup_folder_buttonActionPerformed
/** Open a file and load the image. */ public void openFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); String[] extensions = ImageIO.getReaderFileSuffixes(); chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions)); int r = chooser.showOpenDialog(this); if (r != JFileChooser.APPROVE_OPTION) return; try { Image img = ImageIO.read(chooser.getSelectedFile()); image = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); image.getGraphics().drawImage(img, 0, 0, null); } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } repaint(); }
@Override public void actionPerformed(ActionEvent e) { JFileChooser directoryChooser = new JFileChooser(); directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); directoryChooser.setCurrentDirectory(new File(AbstractDownloader.directory)); directoryChooser.setDialogTitle("Choose directory"); // disable the "All files" option. directoryChooser.setAcceptAllFileFilterUsed(false); if (directoryChooser.showOpenDialog(directoryChooser) == JFileChooser.APPROVE_OPTION) { AbstractDownloader.directory = directoryChooser.getSelectedFile().getAbsolutePath() + "\\"; } else { AbstractDownloader.directory = AbstractDownloader.DEFAULT_DIRECTORY; } // показываем обновленную надпись в label view.getPathTextField().setText(AbstractDownloader.directory); }