How do I open the JavaFX FileChooser from a controller class?
For any node in your scene (for example, the root node; but any node you have injected with @FXML will do), do chooser.showOpenDialog(node.getScene().getWindow());
For any node in your scene (for example, the root node; but any node you have injected with @FXML will do), do chooser.showOpenDialog(node.getScene().getWindow());
You could do: FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(“TXT files (*.txt)”, “*.txt”); chooser.getExtensionFilters().add(extFilter); Here is a simple example: public class ExtensionFilterExample extends Application { public static void main(String[] args) { launch(args); } @Override public void start(final Stage primaryStage) { primaryStage.setTitle(“Extension Filter Example”); final Label fileLabel = new Label(); Button btn = new Button(“Open FileChooser”); btn.setOnAction(new EventHandler<ActionEvent>() … Read more
firstly, sorry to my english. you should return empty Uri[]{} to file receive mUploadMessageForAndroid5.onReceiveValue(new Uri[]{}); my code can choose take photo or local image: private static final int REQUEST_GET_THE_THUMBNAIL = 4000; private static final long ANIMATION_DURATION = 200; public final static int FILECHOOSER_RESULTCODE = 1; public final static int FILECHOOSER_RESULTCODE_FOR_ANDROID_5 = 2; //JS webView.getSettings().setJavaScriptEnabled(true); //set … Read more
It does not appear this is supported in Swing in Java 6. Currently, the simplest way I can find to open this dialog is through SWT, not Swing. SWT’s FileDialog (javadoc) brings up this dialog. The following is a modification of SWT’s FileDialog snippet to use an open instead of save dialog. I know this … Read more
File Browser Update 2016.3.20: Since PowerShell is a native component of all modern Windows installations nowadays, I’m declaring the C# fallback as no longer necessary. If you still need it for Vista or XP compatibility, I moved it to a new answer. Starting with this edit, I’m rewriting the script as a Batch + PowerShell … Read more
A FileChooser is available as part of the JavaFX API. Example usage from javadoc: FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(“Open Resource File”); fileChooser.getExtensionFilters().addAll( new ExtensionFilter(“Text Files”, “*.txt”), new ExtensionFilter(“Image Files”, “*.png”, “*.jpg”, “*.gif”), new ExtensionFilter(“Audio Files”, “*.wav”, “*.mp3”, “*.aac”), new ExtensionFilter(“All Files”, “*.*”)); File selectedFile = fileChooser.showOpenDialog(mainStage); if (selectedFile != null) { mainStage.display(selectedFile); } A … Read more
EDIT (02 Jan 2012): I created a small open source Android Library Project that streamlines this process, while also providing a built-in file explorer (in case the user does not have one present). It’s extremely simple to use, requiring only a few lines of code. You can find it at GitHub: aFileChooser. ORIGINAL If you … Read more
How about using tkinter? from Tkinter import Tk # from tkinter import Tk for Python 3.x from tkinter.filedialog import askopenfilename Tk().withdraw() # we don’t want a full GUI, so keep the root window from appearing filename = askopenfilename() # show an “Open” dialog box and return the path to the selected file print(filename) Done!