Create FileChooser in JavaFX
________________________________________________
import java.io.File;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class JavaFXFileChooser extends Application{
@Override
public void start(Stage stage) {
GridPane pane = new GridPane();
pane.setAlignment(Pos.CENTER);
FileChooser fChooser = new FileChooser();
Button btn = new Button("Select file");
btn.setOnAction(e ->{
File selectedFile = fChooser.showOpenDialog(stage);
});
pane.add(btn, 0, 0);
Scene scene = new Scene(pane, 250, 250);
stage.setTitle("JavaFX FileChooser");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
_____________________________________________
Dark Hers
YouTube
https://instagram.com/darkhers
https://www.facebook.com/darkhers
TikTok
https://www.tiktok.com/@darkhers
https://www.pinterest.co.uk/darkhers
Comments
Post a Comment