I'm learning java swing recently. Please don't tell me it's out of date. I know. I want to create a folder selector like this, there is nothing extra.
Instead of the following, there are many other elements on it
CodePudding user response:
java swing has a jfilechooser
which you can use. refer Java Swing Here
CodePudding user response:
You can use JavaFX:
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setInitialDirectory(new File("src"));
Button button = new Button("Select Directory");
button.setOnAction(e -> {
File selectedDirectory = directoryChooser.showDialog(primaryStage);
System.out.println(selectedDirectory.getAbsolutePath());
});
Javadoc: https://docs.oracle.com/javase/10/docs/api/javafx/stage/DirectoryChooser.html
It does indeed call the Windows browse for folder dialog:
Win32 docs: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shbrowseforfolderw