当前位置: 首页>>代码示例>>Java>>正文


Java FileChooser类代码示例

本文整理汇总了Java中javafx.stage.FileChooser的典型用法代码示例。如果您正苦于以下问题:Java FileChooser类的具体用法?Java FileChooser怎么用?Java FileChooser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileChooser类属于javafx.stage包,在下文中一共展示了FileChooser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateReport

import javafx.stage.FileChooser; //导入依赖的package包/类
/**
 * Generates a PDF report for the
 * user to save wherever they choose
 */
private void generateReport() {

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Save Copy of Report");
    fileChooser.setInitialDirectory(
            new File(System.getProperty("user.home"))
    );
    fileChooser.setInitialFileName("Log Entries.pdf");
    FileChooser.ExtensionFilter pdfExtensionFilter =
            new FileChooser.ExtensionFilter(
                    "PDF - Portable Document Format (.pdf)", "*.pdf");
    fileChooser.getExtensionFilters().add(pdfExtensionFilter);
    fileChooser.setSelectedExtensionFilter(pdfExtensionFilter);
    File file = fileChooser.showSaveDialog(currentStage);

    if (file != null) {
        try {
            exportTableAsPDF(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:kwilliams3,项目名称:Recordian,代码行数:28,代码来源:EditLogEntriesTabController.java

示例2: createSaveFlightButton

import javafx.stage.FileChooser; //导入依赖的package包/类
private Button createSaveFlightButton(Stage stage){
       Button btnSaveFlight = new Button();
       btnSaveFlight.setLayoutX(10);
       btnSaveFlight.setLayoutY(60);;
       btnSaveFlight.setText("Save Flight");

       btnSaveFlight.setOnAction(       
       new EventHandler<ActionEvent>() {
          @Override
          public void handle(final ActionEvent e) {
       	   FileChooser fileChooser = new FileChooser();
      		   fileChooser.setTitle("Flight plan (xml)");
      		   File file = fileChooser.showSaveDialog(stage);
      		   if (file != null) {
      		       System.out.println("Selected " + file);
      		       try {
      		    	    fzv.setPlanningMode(false);
   				    new SaveXMLFlight(file.getAbsolutePath(),wayPoints);
			   } catch (IOException | FlightZoneException e1) {
   					// TODO Auto-generated catch block
   					e1.printStackTrace();
   			   }     
      	    }
       }});
       return btnSaveFlight;
}
 
开发者ID:JaneClelandHuang,项目名称:Dronology,代码行数:27,代码来源:InteractiveFlightPlannerView.java

示例3: exportPackagesButtonPressed

import javafx.stage.FileChooser; //导入依赖的package包/类
public void exportPackagesButtonPressed(ActionEvent evt) throws FileNotFoundException, IOException {
    FileChooser saveChooser = new FileChooser();
    saveChooser.setTitle("Export (Save) data");
    saveChooser.setInitialFileName("package_list.xlsx");
    File saveFile = saveChooser.showSaveDialog(null);
    if (saveFile != null) {
        FileOutputStream out = new FileOutputStream(saveFile);
        String[] headers = new String[]{
            "Group", "Package Name", "Package File", "Size", "Version",
            "Created", "Created By",
            "Last Modified", "Modified By",
            "Last Unpacked", "Unpacked By"
        };
        ReportUtil.exportSpreadsheet(out, packageList, headers,
                PackageType::getGroup, PackageType::getName,
                PackageType::getDownloadName, PackageType::getSize,
                PackageOps::getInformativeVersion,
                PackageType::getCreated, PackageType::getCreatedBy,
                PackageType::getLastModified, PackageType::getLastModifiedBy,
                PackageType::getLastUnpacked, PackageType::getLastUnpackedBy
        );
        out.close();
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:aem-epic-tool,代码行数:25,代码来源:PackageListController.java

示例4: save

import javafx.stage.FileChooser; //导入依赖的package包/类
private void save(DSSDocument signedDocument) {
	FileChooser fileChooser = new FileChooser();
	fileChooser.setInitialFileName(signedDocument.getName());
	MimeType mimeType = signedDocument.getMimeType();
	ExtensionFilter extFilter = new ExtensionFilter(mimeType.getMimeTypeString(), "*." + MimeType.getExtension(mimeType));
	fileChooser.getExtensionFilters().add(extFilter);
	File fileToSave = fileChooser.showSaveDialog(stage);

	if (fileToSave != null) {
		try {
			FileOutputStream fos = new FileOutputStream(fileToSave);
			Utils.copy(signedDocument.openStream(), fos);
			Utils.closeQuietly(fos);
		} catch (Exception e) {
			Alert alert = new Alert(AlertType.ERROR, "Unable to save file : " + e.getMessage(), ButtonType.CLOSE);
			alert.showAndWait();
			return;
		}
	}
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:21,代码来源:SignatureController.java

示例5: selectmultifiles

import javafx.stage.FileChooser; //导入依赖的package包/类
public void selectmultifiles(ActionEvent event) {
	FileChooser fc = new FileChooser();
//	fc.setInitialDirectory(new File("C:\\PdfBox_Examples"));
	fc.getExtensionFilters().addAll(new ExtensionFilter("PDF Files", "*.pdf"));
	selectedFiles = fc.showOpenMultipleDialog(null);

	// FIX - Repeating files in list if ReADDED

	if (selectedFiles != null) {
		for (int i = 0; i < selectedFiles.size(); i++) {
			fileslist.getItems().add(selectedFiles.get(i).getAbsolutePath());
			mylist.add(selectedFiles.get(i).getAbsolutePath());
			NOOFFILES++;
		}
	} else {
		// Provide Error in window
		System.out.println("Invalid File");
	}
}
 
开发者ID:djdivix,项目名称:IDBuilderFX,代码行数:20,代码来源:MultiFileChooserController.java

示例6: initView

import javafx.stage.FileChooser; //导入依赖的package包/类
private void initView() {
    centerArea.getChildren().add(centerBtn);
    centerArea.setAlignment(Pos.CENTER);
    fileTree.setEditable(true);
    fileTree.setCellFactory((TreeView<FileTreeItemModel> tree) -> new FileTreeItemCell());
    mainArea.setTop(topArea);
    mainArea.setCenter(centerArea);
    chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("All Torrent", "*.torrent"));

    //将菜单栏添加到顶部
    topArea.getChildren().add(menuBar);
    errorDialog.setTitle("错误");
    infoDialog.setTitle("提示");

    centerBtn.setOnAction(event -> openFile());
}
 
开发者ID:zhenzou,项目名称:CleanBT,代码行数:17,代码来源:EditorApp.java

示例7: addImage

import javafx.stage.FileChooser; //导入依赖的package包/类
public void addImage(){
	FileChooser fc = new FileChooser();
	fc.setTitle("Select an image for this object!");
	fc.getExtensionFilters().addAll(filts);
	// figure out who the owner is here... 
	File selectedFile = fc.showOpenDialog(App.getMainController().getStage());
	File addedFile = null;
	if(selectedFile == null){
		// they couldn't decide what they want. 
		return; 
	}
	else
	{
		addedFile = App.worldFileUtil.addMultimedia(selectedFile);
	}
	if(addedFile == null){
		log.error("Added file was null!");
	}
	else
	{
		setImageTwo(addedFile);
		changeEvent();
	}
}
 
开发者ID:ForJ-Latech,项目名称:fwm,代码行数:25,代码来源:AddableImage.java

示例8: saveFile

import javafx.stage.FileChooser; //导入依赖的package包/类
public static void saveFile(Stage stage, byte[] bytes) {
    FileChooser chooser = new FileChooser();
    FileChooser.ExtensionFilter lzFilter = new FileChooser.ExtensionFilter("Compressed Bin File (*.bin.lz)",
            "*.bin.lz");
    FileChooser.ExtensionFilter binFilter = new FileChooser.ExtensionFilter("Bin File (*.bin)",
            "*.bin");
    FileChooser.ExtensionFilter allFilter = new FileChooser.ExtensionFilter("All Files",
            "*");
    chooser.getExtensionFilters().addAll(lzFilter, binFilter, allFilter);
    File file = chooser.showSaveDialog(stage);
    if (file != null) {
        try {
            if (file.getName().endsWith("lz")) {
                byte[] compressed = CompressionUtils.compress(bytes);
                Path path = Paths.get(file.getCanonicalPath());
                Files.write(path, compressed);
            } else
                Files.write(Paths.get(file.getCanonicalPath()), bytes);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
 
开发者ID:thane98,项目名称:FEFEditor,代码行数:24,代码来源:FileDialogs.java

示例9: saveAs

import javafx.stage.FileChooser; //导入依赖的package包/类
/**
 * Choose a new file and save the dashboard to that file.
 */
@FXML
private void saveAs() throws IOException {
  FileChooser chooser = new FileChooser();
  chooser.getExtensionFilters().setAll(
      new FileChooser.ExtensionFilter("Shuffleboard Save File (.json)", "*.json"));
  if (currentFile == null) {
    chooser.setInitialDirectory(Storage.getStorageDir());
    chooser.setInitialFileName("shuffleboard.json");
  } else {
    chooser.setInitialDirectory(currentFile.getAbsoluteFile().getParentFile());
    chooser.setInitialFileName(currentFile.getName());
  }

  File selected = chooser.showSaveDialog(root.getScene().getWindow());

  saveFile(selected);
}
 
开发者ID:wpilibsuite,项目名称:shuffleboard,代码行数:21,代码来源:MainWindowController.java

示例10: export

import javafx.stage.FileChooser; //导入依赖的package包/类
@SuppressWarnings("unused")
@FXML
private void export() {
    FileChooser chooser = new FileChooser();
    FileChooser.ExtensionFilter lzFilter = new FileChooser.ExtensionFilter("Compressed Bin File (*.bin.lz)", "*.bin.lz");
    FileChooser.ExtensionFilter binFilter = new FileChooser.ExtensionFilter("Bin File (*.bin)", "*.bin");
    FileChooser.ExtensionFilter allFilter = new FileChooser.ExtensionFilter("All Files", "*");
    chooser.getExtensionFilters().addAll(lzFilter, binFilter, allFilter);
    File file = chooser.showSaveDialog(GuiData.getInstance().getStage());
    if (file != null) {
        try {
            if (file.getName().endsWith("lz")) {
                byte[] compressed = CompressionUtils.compress(bin.toBin());
                Path path = Paths.get(file.getCanonicalPath());
                Files.write(path, compressed);
            } else
                Files.write(Paths.get(file.getCanonicalPath()), bin.toBin());
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
 
开发者ID:thane98,项目名称:FEFEditor,代码行数:23,代码来源:Support.java

示例11: openSpec

import javafx.stage.FileChooser; //导入依赖的package包/类
private void openSpec(ActionEvent t) {
    FileChooser fileChooser = FileChooserFactory
            .createOpenFileChooser(SPECIFICATION,
                    rootModel.get().getWorkingdir());
    File chosenFile = fileChooser
            .showOpenDialog(view.getScene().getWindow());
    if (chosenFile == null) {
        return;
    }
    try {
        HybridSpecification spec = ImporterFacade
                .importHybridSpec(chosenFile,
                        ImporterFacade.ImportFormat.XML);
        this.rootModel.get().getHybridSpecifications().add(spec);
        this.rootModel.get().getHistory()
                .addFilename(chosenFile.getAbsolutePath());
        setWorkingDir(chosenFile);
    } catch (IOException | ImportException e) {
        AlertFactory.createAlert(e).showAndWait();
    }
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:22,代码来源:StvsMenuBarController.java

示例12: handleFileSaveAction

import javafx.stage.FileChooser; //导入依赖的package包/类
@FXML
private void handleFileSaveAction(ActionEvent event) {
    FileChooser fileChooser = new FileChooser();
    File file = fileChooser.showSaveDialog(null);
    
    if (file != null) {
        try {
            WritableImage writableImage = new WritableImage((int) drawingCanvas.getWidth(), (int) drawingCanvas.getHeight());
            drawingCanvas.snapshot(null, writableImage);
            RenderedImage renderedImage = SwingFXUtils.fromFXImage(writableImage, null);            
            ImageIO.write(renderedImage, "png", file);
        } catch (IOException ex) {
            Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
 
开发者ID:kmhasan-class,项目名称:spring2017java,代码行数:17,代码来源:FXMLDocumentController.java

示例13: showFileChooser

import javafx.stage.FileChooser; //导入依赖的package包/类
public static File showFileChooser(Scene scene, FileChooser.ExtensionFilter filter) {
    String home = System.getProperty("user.home");
    File[] downloads = {
            new File(home + "/Downloads/"),
            new File(home + "/Загрузки/"),
            new File(home)
    };
    FileChooser fileChooser = new FileChooser();
    for (File download : downloads) {
        if (download.exists()) {
            fileChooser.setInitialDirectory(download);
            break;
        }
    }
    fileChooser.setSelectedExtensionFilter(filter);
    return fileChooser.showOpenDialog(scene.getWindow());
}
 
开发者ID:KursX,项目名称:Parallator,代码行数:18,代码来源:Helper.java

示例14: btnTDClickedFile

import javafx.stage.FileChooser; //导入依赖的package包/类
@FXML
protected void btnTDClickedFile() throws Exception{
    String path2 = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
    path2 = path2.substring(1, path2.lastIndexOf("/")) + "/";
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open encTitleKeys.bin");
    fileChooser.setInitialDirectory(new File(path2));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("encTitleKeys", "*.bin"));
    File selectedFile = fileChooser.showOpenDialog(btnCancel.getScene().getWindow());

    if(selectedFile != null){
        String path = selectedFile.getPath();
        textTDFile.setText(path);
        path = path.replaceAll(":", "!");
        PropertiesHandler.setProperties(path, "tdfile");
    }
}
 
开发者ID:Ptrk25,项目名称:CDN-FX-2.2,代码行数:18,代码来源:SettingsController.java

示例15: exportBtnHandler

import javafx.stage.FileChooser; //导入依赖的package包/类
/**
 * Asks the user for a filename with a save file dialog, and saves a CSV with the entity clusters
 */
public void exportBtnHandler() {
    FileChooser fileChooser = new FileChooser();

    // Set extension filter
    FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("CSV File", "*.csv");
    fileChooser.getExtensionFilters().add(extFilter);

    // Show save file dialog
    File file = fileChooser.showSaveDialog(containerVBox.getScene().getWindow());

    if (file != null) {
        // Results export to CSV
        try {
            PrintToFile.toCSV(entityClusters, file.getAbsolutePath());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:scify,项目名称:jedai-ui,代码行数:23,代码来源:CompletedController.java


注:本文中的javafx.stage.FileChooser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。