Bonjour tout le monde !

J'ai implémenté une fonction permettant d'afficher une fenêtre pour choisir un fichier (en parcourant le disque) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if( e.getSource() == btnBrowseTarLocation)
   {
    try
    {
     // openinf of a dialog frame to seach the file
     JFrame f = new JFrame();
     FileDialog fd = new FileDialog (f, "Select the file to import", FileDialog.LOAD);
     fd.setFile ("*.*");
     fd.setVisible(true);
 
     // variable in which the path of the selected file will be stocked
     String fileDir = new String();
     String directory = (fd.getDirectory());     // recuperation of the file directory
     String fileName = (fd.getFile());
     fileDir = directory+fileName;
     txtTarLocation.setText(fileDir);
    }
    catch (IllegalArgumentException IlArgE)
    {
       JOptionPane.showMessageDialog(this, "Error with the file dialog", "Error", JOptionPane.ERROR_MESSAGE);
    }
   }
Cependant si je clique sur "annuler" (cad sans choix de fichier), "nullnull" s'affiche dans le JTextField devant contenir le chemin du fichier...

Comment faire pour ne pas avoir ce petit désagrélent ?