This section illustrates you how to browse a file.
In SWT, the class FileDialog allow the user to navigate the file system and select a file name. In order to layout the text, we have used the method text.setLayoutData(data). The method file.isFile() tests whether the file denoted by the pathname is a normal file. The method file.list() returns an array of files and directories. The method text.setText(files[i]) sets the selected file in the text. The method text.setEditable(true) sets the editable state.
Here is the code of FileBrowser.java
Output will be displayed as:
On clicking the browse button, file dialog will open:
After clicking the open button, output will be displayed as:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial