Java Code Examples for javax.swing.JFileChooser#ERROR_OPTION
The following examples show how to use
javax.swing.JFileChooser#ERROR_OPTION .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RobotTree.java From RobotBuilder with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void save() { if (getFilePath() == null) { int result = fileChooser.showSaveDialog(MainFrame.getInstance()); if (result == JFileChooser.CANCEL_OPTION) { return; } else if (result == JFileChooser.ERROR_OPTION) { return; } else if (result == JFileChooser.APPROVE_OPTION) { setFilePath(fileChooser.getSelectedFile().getAbsolutePath()); if (!filePath.endsWith(RobotBuilder.SAVE_FILE_TYPE)) { filePath += "." + RobotBuilder.SAVE_FILE_TYPE; } } } save(filePath); }
Example 2
Source File: VisualMospeed.java From basicv2 with The Unlicense | 6 votes |
private File saveProgram(String targetFile) { Logger.log("Select file to save!"); JFileChooser fc = new JFileChooser(); if (lastDir != null) { fc.setCurrentDirectory(lastDir); } File f = new File(lastDir, targetFile); fc.setSelectedFile(f); int ret = fc.showSaveDialog(frame); if (ret == JFileChooser.CANCEL_OPTION || ret == JFileChooser.ERROR_OPTION) { compile.setEnabled(code != null && code.length > 0); return null; } File file = fc.getSelectedFile(); if (file.isFile()) { boolean ok = file.delete(); if (!ok) { Logger.log("Failed to delete file: " + file); } } return file; }
Example 3
Source File: FileBrowserLine.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void actionPerformed(ActionEvent e) { final int result = browseDialog.showDialog(parent, browseLabel); if (result == JFileChooser.APPROVE_OPTION) { file = browseDialog.getSelectedFile(); } else if (result == JFileChooser.CANCEL_OPTION) { } else if (result == JFileChooser.ERROR_OPTION) { } ignoreTextEvents = true; setText(file.getAbsolutePath()); ignoreTextEvents = false; onFileChanged(); }
Example 4
Source File: MainWinJsApp.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 选择视频文件 * @return */ public boolean openMovFile() { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filter = new FileNameExtensionFilter( "视频文件(*.mkv; *mp4; *.mov; *.avi; *.ts)", "mkv", "mp4", "mov", "avi", "ts"); jfc.setFileFilter(filter); if(MovFileInfo.lastSelPath!=null) { jfc.setCurrentDirectory(new File(MovFileInfo.lastSelPath)); } int status = jfc.showDialog(new JLabel(), "选择视频文件"); if(JFileChooser.APPROVE_OPTION == status) { File file = jfc.getSelectedFile(); if (file != null && file.isFile()) { String filepath = file.getAbsolutePath(); if(file.isDirectory()) { alert("请选择有效的视频文件"); return false; } MovFileInfo.setFile(filepath); return true; } }else if(JFileChooser.ERROR_OPTION == status) { alert("选择文件失败"); return false; } return false; }
Example 5
Source File: MainWinJsApp.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 选择视频文件 * @return */ public boolean openMovFile() { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filter = new FileNameExtensionFilter( "视频文件(*.mkv; *mp4; *.mov; *.avi; *.ts)", "mkv", "mp4", "mov", "avi", "ts"); jfc.setFileFilter(filter); if(MovFileInfo.lastSelPath!=null) { jfc.setCurrentDirectory(new File(MovFileInfo.lastSelPath)); } int status = jfc.showDialog(new JLabel(), "选择视频文件"); if(JFileChooser.APPROVE_OPTION == status) { File file = jfc.getSelectedFile(); if (file != null && file.isFile()) { String filepath = file.getAbsolutePath(); if(file.isDirectory()) { alert("请选择有效的视频文件"); return false; } MovFileInfo.setFile(filepath); return true; } }else if(JFileChooser.ERROR_OPTION == status) { alert("选择文件失败"); return false; } return false; }
Example 6
Source File: AIMerger.java From appinventor-extensions with Apache License 2.0 | 5 votes |
private String getFileToOpen() { JFileChooser projectFC = new JFileChooser(browserPath); int validPath = projectFC.showOpenDialog(myCP); if (validPath == JFileChooser.ERROR_OPTION || validPath == JFileChooser.CANCEL_OPTION) { return null; } else { return projectFC.getSelectedFile().toString(); } }
Example 7
Source File: AIMerger.java From appinventor-extensions with Apache License 2.0 | 5 votes |
private String getFileToOpen() { JFileChooser projectFC = new JFileChooser(); int validPath = projectFC.showOpenDialog(myCP); if (validPath == JFileChooser.ERROR_OPTION || validPath == JFileChooser.CANCEL_OPTION) { return null; } else { return projectFC.getSelectedFile().toString(); } }
Example 8
Source File: StdFileDialog.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Creates a new {@link StdFileDialog}. * * @param comp The parent {@link Component} of the dialog. May be {@code null}. * @param title The title to use. May be {@code null}. * @param accessoryPanel An extra panel to show. May be {@code null}. * @param filters The file filters to make available. If there are none, then the {@code * showAllFilter} flag will be forced to {@code true}. * @return The chosen {@link Path} or {@code null}. */ public static Path showOpenDialog(Component comp, String title, JComponent accessoryPanel, FileNameExtensionFilter... filters) { Preferences prefs = Preferences.getInstance(); JFileChooser dialog = new JFileChooser(prefs.getLastDir().toFile()); dialog.setDialogTitle(title); if (filters != null && filters.length > 0) { dialog.setAcceptAllFileFilterUsed(false); for (FileNameExtensionFilter filter : filters) { dialog.addChoosableFileFilter(filter); } } else { dialog.setAcceptAllFileFilterUsed(true); } if (accessoryPanel != null) { dialog.setAccessory(accessoryPanel); } int result = dialog.showOpenDialog(comp); if (result != JFileChooser.ERROR_OPTION) { File current = dialog.getCurrentDirectory(); if (current != null) { prefs.setLastDir(current.toPath()); } } if (result == JFileChooser.APPROVE_OPTION) { Path path = dialog.getSelectedFile().toPath().normalize().toAbsolutePath(); prefs.addRecentFile(path); return path; } return null; }
Example 9
Source File: RobotTree.java From RobotBuilder with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void load() { if (OKToClose()) { int result = fileChooser.showOpenDialog(MainFrame.getInstance()); if (result == JFileChooser.CANCEL_OPTION) { return; } else if (result == JFileChooser.ERROR_OPTION) { return; } else if (result == JFileChooser.APPROVE_OPTION) { setFilePath(fileChooser.getSelectedFile().getAbsolutePath()); } load(new File(filePath)); } }
Example 10
Source File: VisualMospeed.java From basicv2 with The Unlicense | 5 votes |
private void loadProgram() { JFileChooser fc = new JFileChooser(); if (lastDir != null) { fc.setCurrentDirectory(lastDir); } int ret = fc.showOpenDialog(frame); if (ret == JFileChooser.CANCEL_OPTION || ret == JFileChooser.ERROR_OPTION) { compile.setEnabled(code != null && code.length > 0); return; } load(fc.getSelectedFile()); }
Example 11
Source File: VisualRuntime.java From basicv2 with The Unlicense | 5 votes |
public void loadProgram() { run.setText("RUN"); JFileChooser fc = new JFileChooser(); if (lastDir != null) { fc.setCurrentDirectory(lastDir); } int ret = fc.showOpenDialog(frame); if (ret == JFileChooser.CANCEL_OPTION || ret == JFileChooser.ERROR_OPTION) { run.setEnabled(code != null && code.length > 0); return; } File file = fc.getSelectedFile(); code = Loader.loadProgram(file.toString()); lastDir = file.getParentFile(); for (String line : code) { line = line.trim(); if (!line.isEmpty()) { if (!Character.isDigit(line.charAt(0))) { code = Preprocessor.convertToLineNumbers(code); JOptionPane.showMessageDialog(frame, "Program converted from labels to line numbers!"); } } break; } run.setEnabled(true); frame.setTitle(file.getName()); }
Example 12
Source File: OnClickListener.java From CEC-Automatic-Annotation with Apache License 2.0 | 5 votes |
public void handleSaveAsFile() { // FileDialog fileDialog = new // FileDialog(getJFrame(),"保存...",FileDialog.SAVE); // fileDialog.setVisible(true); // String fileName = fileDialog.getDirectory()+fileDialog.getFile(); // 设置对话框的风格 try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e1) { MyLogger.logger.info("设置对话框风格出错!" + e1.getMessage()); e1.printStackTrace(); } JFileChooser jFileChooser = new JFileChooser(); // jFileChooser.setMultiSelectionEnabled(true);//如果要多选的话,设置这句话即可 // 设置默认的保存文件名称 // jFileChooser.setSelectedFile(new // File(getTitleContent().getText().toString())); int result = jFileChooser.showSaveDialog(null); switch (result) { case JFileChooser.APPROVE_OPTION: // 这一种方法是把显示内容中的标题取出来作为文件名,暂不采用 // filePath = jFileChooser.getCurrentDirectory() + File.separator + // getTitleContent().getText() + ".xml"; // 这一种方法是把用户输入的作为保存的文件名 filePath = jFileChooser.getCurrentDirectory() + File.separator + jFileChooser.getSelectedFile().getName() + ".xml"; MyLogger.logger.info("改变路径之后,文件的保存路径=" + filePath); MyLogger.logger.info("Approve (Open or Save) was clicked "); MyLogger.logger.info("这是绝对路径:" + jFileChooser.getSelectedFile().getAbsolutePath()); writeToFile(filePath); break; case JFileChooser.CANCEL_OPTION: MyLogger.logger.info("Cancle or the close-dialog icon was clicked"); break; case JFileChooser.ERROR_OPTION: MyLogger.logger.error("Error..."); break; } }
Example 13
Source File: AsyncFileChooser.java From osp with GNU General Public License v3.0 | 5 votes |
private int err() { try { throw new java.lang.IllegalAccessException("Warning! AsyncFileChooser interface bypassed!"); } catch (IllegalAccessException e) { e.printStackTrace(); } return JFileChooser.ERROR_OPTION; }
Example 14
Source File: JavaFXFileChooser.java From keystore-explorer with GNU General Public License v3.0 | 4 votes |
public int showFxDialog(final String method) { try { final Object fileChooser = fileChooserClass.getConstructor().newInstance(); selectedFile = runLater(new Callable<File>() { @Override public File call() throws Exception { // set extension filters Method getExtensionFiltersMethod = fileChooserClass.getMethod("getExtensionFilters"); List<Object> observableList = (List<Object>) getExtensionFiltersMethod.invoke(fileChooser); observableList.add(extensionFilterClass.getConstructor(String.class, String[].class) .newInstance(res.getString("JavaFXFileChooser.AllFiles"), new String[] { "*.*" })); for (FileExtFilter fileFilter : filters) { // convert format for extensions String[] extensions = fileFilter.getExtensions(); for (int i = 0; i < extensions.length; i++) { if (!extensions[i].startsWith("*.")) { extensions[i] = "*." + extensions[i]; } } Object extFilter = extensionFilterClass.getConstructor(String.class, String[].class) .newInstance(fileFilter.getDescription(), extensions); observableList.add(extFilter); } // set window title Method setTitleMethod = fileChooserClass.getMethod("setTitle", String.class); setTitleMethod.invoke(fileChooser, dialogTitle); // set current directory Method setInitialDirectory = fileChooserClass.getMethod("setInitialDirectory", File.class); setInitialDirectory.invoke(fileChooser, currentDirectory); Method showDialogMethod = fileChooserClass.getMethod(method, windowClass); Object file = showDialogMethod.invoke(fileChooser, (Object) null); return (File) file; } }); } catch (Exception e) { return JFileChooser.ERROR_OPTION; } if (selectedFile == null) { return JFileChooser.CANCEL_OPTION; } return JFileChooser.APPROVE_OPTION; }