當前位置: 首頁>>代碼示例>>Java>>正文


Java FileChooser.showOpenDialog方法代碼示例

本文整理匯總了Java中javafx.stage.FileChooser.showOpenDialog方法的典型用法代碼示例。如果您正苦於以下問題:Java FileChooser.showOpenDialog方法的具體用法?Java FileChooser.showOpenDialog怎麽用?Java FileChooser.showOpenDialog使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.stage.FileChooser的用法示例。


在下文中一共展示了FileChooser.showOpenDialog方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleSelectImage

import javafx.stage.FileChooser; //導入方法依賴的package包/類
public void handleSelectImage(MouseEvent mouseEvent) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(imageChooserTitle);
    fileChooser.getExtensionFilters().add(new ExtensionFilter("PNG", "*.png"));
    final File file = fileChooser
        .showOpenDialog(((Node) mouseEvent.getSource()).getScene().getWindow());
    if (file == null) {
        return;
    }

    try {
        final byte[] image = ImageUtils.readImage(file);
        model.imageRaw.set(image);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:18,代碼來源:ItemArmorController.java

示例2: loadAppListFromXml

import javafx.stage.FileChooser; //導入方法依賴的package包/類
@FXML
private void loadAppListFromXml(ActionEvent event)
{
    try
    {
        FileChooser fc = new FileChooser();
        File file = fc.showOpenDialog(null);


        if (file != null)
        {
            prefs.put(PreferencesKeys.SAVE_PATH.toString(), file.getAbsolutePath());
            userAppList.loadFromXml(file);
            this.updateListApp();
        }

    } catch (Exception e)
    { // catches ANY exception
        e.printStackTrace();
        JFXSnackbar info = new JFXSnackbar(root);
        info.show(I18n.getMessage("errorloadsave"), 3000);
    }
}
 
開發者ID:Matthieu42,項目名稱:Steam-trader-tools,代碼行數:24,代碼來源:AppController.java

示例3: openSession

import javafx.stage.FileChooser; //導入方法依賴的package包/類
private void openSession(ActionEvent t) {
    FileChooser fileChooser = FileChooserFactory
            .createOpenFileChooser(SESSION,
                    rootModel.get().getWorkingdir());
    File chosenFile = fileChooser
            .showOpenDialog(view.getScene().getWindow());

    if (chosenFile == null) {
        return;
    }
    try {
        StvsRootModel model = ImporterFacade
                .importSession(chosenFile, ImporterFacade.ImportFormat.XML,
                        rootModel.get().getGlobalConfig(),
                        rootModel.get().getHistory());
        setWorkingDir(chosenFile);
        model.setFilename(chosenFile.getName());
        this.rootModel.set(model);
        this.rootModel.get().getHistory()
                .addFilename(chosenFile.getAbsolutePath());
    } catch (IOException | ImportException exception) {
        AlertFactory.createAlert(exception).showAndWait();
    }
}
 
開發者ID:VerifAPS,項目名稱:stvs,代碼行數:25,代碼來源:StvsMenuBarController.java

示例4: getRestore

import javafx.stage.FileChooser; //導入方法依賴的package包/類
public String getRestore(){
	String backuppath ="";
	File file;
	FileChooser fileChooser= new FileChooser();
	file = fileChooser.showOpenDialog(stage);
	fileChooser.setTitle("Select Photo");
       if (file != null) {
       	fileChooser.getExtensionFilters().addAll(
       		    new FileChooser.ExtensionFilter("All Images", "*.*"),
       		    new FileChooser.ExtensionFilter("SQL", "*.sql")
       );
       	
       	backuppath = file.getAbsolutePath();      
}
	return backuppath;
}
 
開發者ID:mikemacharia39,項目名稱:gatepass,代碼行數:17,代碼來源:Restore.java

示例5: selectExpressionXMLFile

import javafx.stage.FileChooser; //導入方法依賴的package包/類
public static File selectExpressionXMLFile(Window ownerWindow)
        throws IOException, JAXBException, SAXException {
    File retVal = null;

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Select Expression xml File '.xml");
    fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Expression xml Files", "*.xml"));
    File mruFolder = new File(squidPersistentState.getMRUExpressionFolderPath());
    fileChooser.setInitialDirectory(mruFolder.isDirectory() ? mruFolder : null);

    File expressionFileXML = fileChooser.showOpenDialog(ownerWindow);

    if (expressionFileXML != null) {
        if (expressionFileXML.getName().toLowerCase(Locale.US).endsWith(".xml")) {
            squidPersistentState.setMRUExpressionFolderPath(expressionFileXML.getParent());
            retVal = expressionFileXML;
        } else {
            throw new IOException("Filename does not end with '.xml'");
        }
    }

    return retVal;
}
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:24,代碼來源:FileHandler.java

示例6: changePhoto

import javafx.stage.FileChooser; //導入方法依賴的package包/類
@FXML
public void changePhoto(ActionEvent event) throws IOException {
	FileChooser fileChooser = new FileChooser();
	fileChooser.setInitialDirectory(new File("C:\\PdfBox_Examples"));
	FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
	FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
	FileChooser.ExtensionFilter extFilterJPEG = new FileChooser.ExtensionFilter("JPEG Files (*.jpeg)", "*.JPEG");
	fileChooser.getExtensionFilters().addAll(extFilterJPG, extFilterPNG, extFilterJPEG);
	File selectedFile = fileChooser.showOpenDialog(null);
	if (selectedFile != null) {
		BufferedImage img1 = ImageIO.read(new File(selectedFile.getAbsolutePath()));
		Image image = SwingFXUtils.toFXImage(img1, null);
		photo.setImage(image);
		photo.setPreserveRatio(true);
	}
}
 
開發者ID:djdivix,項目名稱:IDBuilderFX,代碼行數:17,代碼來源:ViewSingleParsedController.java

示例7: openFileAction

import javafx.stage.FileChooser; //導入方法依賴的package包/類
/**
 * Opens a {@link FileChooser} and sets the parent {@link javafx.stage.Window} as
 * {@link Hygene#getPrimaryStage()#getOwner()}.
 *
 * @param fileChooser the file chooser that needs to be shown to the user
 * @param type        a descriptive type name of the file that needs to be opened
 * @return a file object or {@code null} if no file was selected
 * @throws IOException               if unable to open or parse the file
 * @throws UIInitialisationException if this method was called before {@link Hygene} was instantiated
 */
private File openFileAction(final FileChooser fileChooser, final String type)
        throws UIInitialisationException, IOException {
    final Stage primaryStage = Hygene.getInstance().getPrimaryStage();

    final File recentDirectory = RecentDirectory.get(type);
    if (recentDirectory.exists()) {
        fileChooser.setInitialDirectory(recentDirectory);
    }

    final File file = fileChooser.showOpenDialog(primaryStage.getScene().getWindow());
    if (file == null) {
        return null;
    }

    if (file.getParentFile() != null) {
        RecentDirectory.store(type, file.getParentFile());
    }

    return file;
}
 
開發者ID:ProgrammingLife2017,項目名稱:hygene,代碼行數:31,代碼來源:MenuController.java

示例8: handleOpen

import javafx.stage.FileChooser; //導入方法依賴的package包/類
@FXML
private void handleOpen() {
	Alert alert = new Alert(AlertType.CONFIRMATION);
	alert.setTitle("Confirmation Dialog");
	alert.setHeaderText("Do you want to save your current changes?");
	alert.setContentText("");
	
	Optional<ButtonType> result = alert.showAndWait();
	if (result.get() == ButtonType.OK){ 
		File entryFile = mainApp.getFilePath();
		mainApp.saveEntryDataToFile(entryFile);
	}
	
	FileChooser fileChooser = new FileChooser();
	
	// set extension filter
	FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML files (*.xml)", "*.xml");
	fileChooser.getExtensionFilters().add(extFilter);
	
	// show open file dialog
	File file = fileChooser.showOpenDialog(mainApp.getPrimaryStage());
	
	if (file != null) {
		mainApp.loadEntryDataFromFile(file);
	}
}
 
開發者ID:yc45,項目名稱:kanphnia2,代碼行數:27,代碼來源:RootLayoutController.java

示例9: getClickAction

import javafx.stage.FileChooser; //導入方法依賴的package包/類
@Override
public void getClickAction(final Dictionary dictionary, final Stage stage, final TabFactory tabFactory, final DialogFactory dialogFactory) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.getExtensionFilters().add(FileExtensionFilters.MARKDOWN);
    File file = fileChooser.showOpenDialog(stage);
    if(file != null){
        try {
            EditorTab tab = ((EditorTab)tabFactory.getSelectedTab());
            tab.getEditorPane().setContent(tab.getEditorPane().getContent() + "\n" + new Scanner(file).useDelimiter("\\Z").next());
        } catch (IOException e1) {
            dialogFactory.buildExceptionDialogBox(
                    dictionary.DIALOG_EXCEPTION_TITLE,
                    dictionary.DIALOG_EXCEPTION_IMPORT_CONTENT,
                    e1.getMessage(),
                    e1
            ).showAndWait();
        }
    }
}
 
開發者ID:jdesive,項目名稱:textmd,代碼行數:20,代碼來源:EditorImportFileItem.java

示例10: getAttributeFromFile

import javafx.stage.FileChooser; //導入方法依賴的package包/類
public SpriteMakerModel getAttributeFromFile() {
	XStream xstream = new XStream(new DomDriver());
	FileChooser chooser = new FileChooser();
	File attributeFile = chooser.showOpenDialog(new Stage());
	SpriteMakerModel attribute = (SpriteMakerModel)xstream.fromXML(attributeFile);
	return attribute;
}
 
開發者ID:LtubSalad,項目名稱:voogasalad-ltub,代碼行數:8,代碼來源:XStreamHandler.java

示例11: getScriptPath

import javafx.stage.FileChooser; //導入方法依賴的package包/類
private void getScriptPath(Stage primaryStage) {
	if (scriptPath.isEmpty()) {
		FileChooser fileChooser = new FileChooser();
		 fileChooser.setTitle("Choose Script");
		 fileChooser.getExtensionFilters().addAll(
		         new ExtensionFilter("Lua Scripts", "*.lua"),
		         new ExtensionFilter("All Files", "*.*"));
		 File selectedFile = fileChooser.showOpenDialog(primaryStage);
		 if (selectedFile != null) {
			 scriptPath = selectedFile.getAbsolutePath();
		 }
	}
}
 
開發者ID:joakimkistowski,項目名稱:HTTP-Load-Generator,代碼行數:14,代碼來源:ScriptTestWindow.java

示例12: randomizeWithSettings

import javafx.stage.FileChooser; //導入方法依賴的package包/類
@FXML
private void randomizeWithSettings() {
    FileChooser chooser = new FileChooser();
    chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(
            "JSON Files (*.json)", "*.json"));
    File file = chooser.showOpenDialog(Gui.getInstance().getMainStage());
    try {
        Type type = new TypeToken<SettingsWrapper>() {
        }.getType();
        Gson gson = new Gson();
        JsonReader reader = new JsonReader(new BufferedReader(new FileReader(file)));
        SettingsWrapper wrapper = gson.fromJson(reader, type);
        reader.close();
        FatesGui.getInstance().setSelectedOptions(wrapper.getGui().getSelectedOptions());
        FatesGui.getInstance().setSelectedPaths(wrapper.getGui().getSelectedPaths());
        FatesGui.getInstance().setSelectedItems(wrapper.getGui().getSelectedItems());
        FatesGui.getInstance().setSelectedSkills(wrapper.getGui().getSelectedSkills());
        if (wrapper.getGui().getSelectedPaths()[0] && !FatesFiles.getInstance().isBirthrightVerified()) {
            throwUnverifiedPathDialog();
            return;
        }
        if (wrapper.getGui().getSelectedPaths()[1] && !FatesFiles.getInstance().isConquestVerified()) {
            throwUnverifiedPathDialog();
            return;
        }
        if (wrapper.getGui().getSelectedPaths()[2] && !FatesFiles.getInstance().isRevelationVerified()) {
            throwUnverifiedPathDialog();
            return;
        }
        List<FatesCharacter> selectedCharacters = wrapper.getCharacters();
        loadCodeBin();
        FatesHub hub = new FatesHub();
        hub.randomizeWithSettings(selectedCharacters);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:thane98,項目名稱:3DSFE-Randomizer,代碼行數:38,代碼來源:FatesOptions.java

示例13: open

import javafx.stage.FileChooser; //導入方法依賴的package包/類
@FXML
public void open() {
  FileChooser fileChooser = new FileChooser();
  fileChooser.setTitle("Open");
  fileChooser.getExtensionFilters().add(new ExtensionFilter("Style Sheet", "*.css"));
  fileChooser.setInitialDirectory(recentSupport.getLastFile().getParentFile());
  File selectedFile = fileChooser.showOpenDialog(stage);
  if (selectedFile != null) {
    openFile(selectedFile);
  }
}
 
開發者ID:XDean,項目名稱:CSS-Editor-FX,代碼行數:12,代碼來源:MainFrameController.java

示例14: loadPlayback

import javafx.stage.FileChooser; //導入方法依賴的package包/類
@FXML
private void loadPlayback() throws IOException {
  FileChooser chooser = new FileChooser();
  chooser.setInitialDirectory(Storage.getRecordingDir());
  chooser.getExtensionFilters().setAll(
      new FileChooser.ExtensionFilter("Shuffleboard Data Recording", "*.sbr"));
  final File selected = chooser.showOpenDialog(root.getScene().getWindow());
  if (selected == null) {
    return;
  }
  Playback playback = Playback.load(selected.getAbsolutePath());
  playback.start();
}
 
開發者ID:wpilibsuite,項目名稱:shuffleboard,代碼行數:14,代碼來源:MainWindowController.java

示例15: selectfile

import javafx.stage.FileChooser; //導入方法依賴的package包/類
public void selectfile(ActionEvent event) {
	FileChooser fc = new FileChooser();
//	fc.setInitialDirectory(new File("C:\\PdfBox_Examples"));
	fc.getExtensionFilters().addAll(new ExtensionFilter("PDF Files", "*.pdf"));
	selectedFile = fc.showOpenDialog(null);

	if (selectedFile != null) {
		fclabel.setText(selectedFile.getAbsolutePath());
	} else {
		fclabel.setText("Invalid File");
	}
}
 
開發者ID:djdivix,項目名稱:IDBuilderFX,代碼行數:13,代碼來源:FileChooserController.java


注:本文中的javafx.stage.FileChooser.showOpenDialog方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。