本文整理汇总了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();
}
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
}
示例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");
}
}
示例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());
}
示例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();
}
}
示例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();
}
}
}
示例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);
}
示例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();
}
}
}
示例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();
}
}
示例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);
}
}
}
示例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());
}
示例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");
}
}
示例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();
}
}
}