Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use FileDialog?

Tags:

I created an interface and I'd like to add a function that allows user to open a file. I'm using AWT. I don't understand how to use FileDialog. Can you please give me an example or a good link that explain this?

like image 807
grb Avatar asked Aug 26 '11 22:08

grb


People also ask

How do I use FileDialog in Python?

Use the askopenfilename() function to display an open file dialog that allows users to select one file. Use the askopenfilenames() function to display an open file dialog that allows users to select multiple files.

How do I use FileDialog in VBA?

Excel VBA FileDialog – Example #1Step 1: Go to the Developers tab and click on Visual Basic. Step 2: Open a Module from the Insert menu option as shown below. Step 3: Start the subprocedure to start working on example. Step 4: Declare a variable as Filedialog as shown below.

What is FileDialog in Java?

The FileDialog class displays a dialog window from which the user can select a file. Since it is a modal dialog, when the application calls its show method to display the dialog, it blocks the rest of the application until the user has chosen a file.

How do I open a dialog box in access?

To open the Access Options dialog box, click the File tab on the Backstage view and then click Options, as shown in Figure 2-98. Figure 2-98. Click the File tab on the Backstage view and then click Options to open the Access Options dialog box.


1 Answers

A complete code example, with file filtering:

FileDialog fd = new FileDialog(yourJFrame, "Choose a file", FileDialog.LOAD); fd.setDirectory("C:\\"); fd.setFile("*.xml"); fd.setVisible(true); String filename = fd.getFile(); if (filename == null)   System.out.println("You cancelled the choice"); else   System.out.println("You chose " + filename); 
like image 61
Salvatorelab Avatar answered Sep 24 '22 00:09

Salvatorelab