本文整理汇总了Java中javafx.stage.DirectoryChooser类的典型用法代码示例。如果您正苦于以下问题:Java DirectoryChooser类的具体用法?Java DirectoryChooser怎么用?Java DirectoryChooser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectoryChooser类属于javafx.stage包,在下文中一共展示了DirectoryChooser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveDirectory
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
@FXML private void saveDirectory() {
try {
BetonQuestEditor instance = BetonQuestEditor.getInstance();
DirectoryChooser dc = new DirectoryChooser();
dc.setTitle(instance.getLanguage().getString("select-directory"));
File desktop = new File(System.getProperty("user.home") + File.separator + "Desktop");
if (desktop != null) dc.setInitialDirectory(desktop);
File selectedFile = dc.showDialog(instance.getPrimaryStage());
if (selectedFile != null) {
PackageSet set = BetonQuestEditor.getInstance().getDisplayedPackage().getSet();
set.saveToDirectory(selectedFile);
set.setSaveType(SaveType.DIR);
set.setFile(selectedFile);
MainMenuController.setSaveEnabled(true);
}
} catch (Exception e) {
ExceptionController.display(e);
}
}
示例2: openDialogue
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
private void openDialogue() {
DirectoryChooser chooser = new DirectoryChooser();
File file = chooser.showDialog(GuiData.getInstance().getStage());
if (file != null) {
try {
FileData.getInstance().setWorkingFile(file);
FXMLLoader loader = new FXMLLoader(FEFEditor.class.getResource("gui/fxml/fates/Dialogue.fxml"));
content = loader.load();
changeContent();
Dialogue controller = loader.getController();
controller.addAccelerators();
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例3: addCharacter
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
@FXML
private void addCharacter() {
DirectoryChooser chooser = new DirectoryChooser();
File file = chooser.showDialog(GuiData.getInstance().getStage());
if (file != null) {
TextInputDialog dialog = new TextInputDialog("placeholder");
dialog.setTitle("Name Input");
dialog.setHeaderText("Name Input");
dialog.setContentText("Please enter the voice set name:");
Optional<String> result = dialog.showAndWait();
result.ifPresent(name -> bin.addEntries(name, file));
entryList.getItems().clear();
groupList.getItems().clear();
selectedEntry = null;
selectedGroup = null;
for (VoiceGroup v : bin.getEntries()) {
groupList.getItems().add(v.getMainLabel());
}
}
}
示例4: configureDirectoryChooser
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
private static DirectoryChooser configureDirectoryChooser(File initDir) {
// fileChooser.setTitle("View Pictures");
DirectoryChooser dirChooser = new DirectoryChooser();
if (initDir != null && initDir.exists()) {
if (initDir.isDirectory()) {
dirChooser.setInitialDirectory(initDir);
} else {
dirChooser.setInitialDirectory(initDir.getParentFile());
}
} else {
dirChooser.setInitialDirectory(
new File(System.getProperty("user.home")));
}
return dirChooser;
}
示例5: start
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
@Override public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Simple Web Server");
BorderPane root = new BorderPane();
TextArea area = new TextArea();
root.setCenter(area);
ToolBar bar = new ToolBar();
Button openInBrowser = FXUIUtils.createButton("open-in-browser", "Open in External Browser", true);
openInBrowser.setOnAction((event) -> {
try {
Desktop.getDesktop().browse(URI.create(webRoot));
} catch (IOException e) {
e.printStackTrace();
}
});
Button changeRoot = FXUIUtils.createButton("fldr_closed", "Change Web Root", true);
changeRoot.setOnAction((event) -> {
DirectoryChooser chooser = new DirectoryChooser();
File showDialog = chooser.showDialog(primaryStage);
if (showDialog != null)
server.setRoot(showDialog);
});
bar.getItems().add(openInBrowser);
bar.getItems().add(changeRoot);
root.setTop(bar);
System.setOut(new PrintStream(new Console(area)));
System.setErr(new PrintStream(new Console(area)));
area.setEditable(false);
primaryStage.setScene(new Scene(root));
primaryStage.setOnShown((e) -> startServer(getParameters().getRaw()));
primaryStage.show();
}
示例6: start
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
@Override public void start(final Stage stage) {
stage.setTitle("Directory Chooser Sample");
final DirectoryChooser directoryChooser = new DirectoryChooser();
final Button openButton = new Button("Select a folder...");
openButton.setOnAction((final ActionEvent e) -> {
File file = directoryChooser.showDialog(stage);
if (file != null) {
openFile(file);
}
});
final GridPane inputGridPane = new GridPane();
GridPane.setConstraints(openButton, 0, 1);
inputGridPane.setHgap(6);
inputGridPane.setVgap(6);
inputGridPane.getChildren().addAll(openButton);
final Pane rootGroup = new VBox(12);
rootGroup.getChildren().addAll(inputGridPane);
rootGroup.setPadding(new Insets(12, 12, 12, 12));
stage.setScene(new Scene(rootGroup));
stage.show();
}
示例7: exportAllGroups
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
public void exportAllGroups() {
LOGGER.traceEntry();
if (!isCatalogueLoaded()) {
LOGGER.debug(":exportAllGroups - No catalogue set. Returning");
return;
}
DirectoryChooser dc = new DirectoryChooser();
if (manager.hasLastExportLocation()) {
dc.setInitialDirectory(manager.getLastExportLocation());
}
dc.setTitle("Choose an export folder");
File dir = dc.showDialog(evaluator.getScene().getWindow());
for (Group g : manager.groupList()) {
assemble(g);
}
manager.exportAllGroups(dir);
}
示例8: showDirectoryChooser
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
public static File showDirectoryChooser(Scene scene) {
String home = System.getProperty("user.home");
File[] downloads = {
new File(home + "/Downloads/"),
new File(home + "/Загрузки/"),
new File(home)
};
DirectoryChooser fileChooser = new DirectoryChooser();
for (File download : downloads) {
if (download.exists()) {
fileChooser.setInitialDirectory(download);
break;
}
}
return fileChooser.showDialog(scene.getWindow());
}
示例9: getInstallDir
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
public static void getInstallDir(Predicate<File> predicate) throws IOException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL fxmlUrl = classLoader.getResource("gui/install_location.fxml");
if (fxmlUrl == null) {
OneClientLogging.logger.error("An error has occurred loading the fxml!");
}
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(fxmlUrl);
fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
Parent root = fxmlLoader.load(fxmlUrl.openStream());
Stage stage = new Stage();
stage.setTitle("Select Install Location");
stage.getIcons().add(new Image("images/icon.png"));
stage.setResizable(false);
stage.initOwner(Main.stage);
stage.initModality(Modality.WINDOW_MODAL);
Scene scene = new Scene(root, 500, 150);
scene.getStylesheets().add("gui/css/theme.css");
stage.setScene(scene);
stage.show();
InstallLocation controller = fxmlLoader.getController();
controller.okButton.setOnAction(event -> {
predicate.test(new File(controller.locationField.getText()));
stage.close();
});
controller.browseButton.setOnAction(event -> {
DirectoryChooser directoryChooser = new DirectoryChooser();
File dir = new File(controller.locationField.getText());
if (dir.exists())
directoryChooser.setInitialDirectory(dir);
File selectedDirectory = directoryChooser.showDialog(stage);
if (selectedDirectory != null) {
controller.locationField.setText(selectedDirectory.getAbsolutePath());
}
});
controller.locationField.setText(Constants.getDefaultDir().getAbsolutePath());
}
示例10: pickAndReadAudioFilesFromFolder
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
private void pickAndReadAudioFilesFromFolder(final Stage primaryStage, final VBox vboxPlaylist) {
final DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Find a folder with audio files");
final File selectedDirectory = directoryChooser.showDialog(primaryStage);
if (selectedDirectory != null) {
final File[] listFiles = selectedDirectory.listFiles();
if (listFiles != null) {
LOGGER.info("Found " + listFiles.length + " files");
Arrays.stream(listFiles)
.filter(file -> !file.isDirectory())
.filter(file -> {
final String extension = FilenameUtils.getExtension(file.getPath());
return extension.equals(MP3) || extension.equals(M4A);
})
.forEach(file -> {
LOGGER.info("Trying to load from the file: " + file.getPath());
try {
readFileAndSetInitialStateForAudioItem(file, vboxPlaylist);
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
}
示例11: handleSelectFolder
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
/**
* Open a DirectoryChooser window.
*/
@FXML
private void handleSelectFolder() {
final DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle(Locale.getString("directory.chooser.title")); //$NON-NLS-1$
if (!this.textAreaSaveDirectory.getText().isEmpty()) {
final File defaultDirectory = new File(this.textAreaSaveDirectory.getText());
if (defaultDirectory.exists()) {
chooser.setInitialDirectory(defaultDirectory);
}
}
final File selectedDirectory = chooser.showDialog(this.app.getPrimaryStage());
if (selectedDirectory != null) {
this.textAreaSaveDirectory.setText(selectedDirectory.toString());
}
}
示例12: selectStorageDirectory
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
@FXML
private void selectStorageDirectory() {
Stage stage = (Stage) root.getScene().getWindow();
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Open Telemetry Storage Directory");
directoryChooser.setInitialDirectory(
new File(System.getProperty("user.home")));
File directory = directoryChooser.showDialog(stage);
if (directory != null && directory.isDirectory()) {
try {
String directoryName = directory.getCanonicalPath();
txtStorageDirectory.setText(directoryName);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例13: showDirSaveDialog
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
public static File showDirSaveDialog(Window ownerWindow, File initDir, Consumer<DirectoryChooser> option) {
DirectoryChooser chooser = new DirectoryChooser();
chooser.setInitialDirectory(initDir);
chooser.setTitle("Directory");
if (option != null)
option.accept(chooser);
File selectedDir = chooser.showDialog(ownerWindow);
if (selectedDir != null && selectedDir.exists()) {
applyLastPath(selectedDir);
}
return selectedDir;
}
示例14: handleBrowse
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
private void handleBrowse(Event event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Export Ort wählen");
if (exportFolder != null) {
directoryChooser.setInitialDirectory(new File(exportFolder));
}
File directory = directoryChooser.showDialog(null);
if (directory == null || !directory.exists()) {
getLogger().info("Invalid directory selected.");
return;
}
directoryField.setText(directory.getPath());
exportFolder = directory.getPath();
}
示例15: chooseAndSetDirectory
import javafx.stage.DirectoryChooser; //导入依赖的package包/类
/**
* Opens directory chooser
*/
private void chooseAndSetDirectory() {
DirectoryChooser fileChooser = new DirectoryChooser();
fileChooser.setTitle(Util.text("choose-directory-window-name"));
Session.DIRECTORY = !Settings.getSetting("path").isEmpty()
? new File(Settings.getSetting("path"))
: null;
fileChooser.setInitialDirectory(Session.DIRECTORY);
File file;
try {
file = fileChooser.showDialog(stage);
} catch (IllegalArgumentException ex) {
fileChooser.setInitialDirectory(null);
file = fileChooser.showDialog(stage);
}
if (file != null) {
Session.DIRECTORY = file;
browsePath.setText(file.getAbsolutePath());
Settings.setSetting("path", Session.DIRECTORY.getAbsolutePath());
getFileListByDirectory(file);
}
}