Javatpoint Logo
Javatpoint Logo

JavaFX FileChooser

JavaFX File chooser enables users to browse the files from the file system. javafx.stage.FileChooser class represents FileChooser. It can be created by instantiating FileChooser class. It contains two main methods.

As we see in the modern day applications, there are two types of dialogues shown to the user, one is for opening the file and the other is for saving the files. In each case, the user needs to browse a location for the file and give the name to the file.

The FileChooser class provides two types of methods,

  1. showOpenDialog()
  2. showSaveDialog()

The following code implements showSaveDialog() method.

Example 1:


The above code shows the following dialogue box to the user where user is prompted to browse the location of the file which needs to be opened.


JavaFX FileChooser

Example 2:

The following code shows a Label, TextField and a Button to the user. An open file dialogue box will open on clicking the browse button.

Output:


JavaFX FileChooser 1

Saving Files

The following code shows the dialogue box for saving the files.

Output:


JavaFX FileChooser 2
JavaFX FileChooser 3
JavaFX FileChooser 4
Next TopicJavaFX Menu




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA