當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。