• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

FileChooser

I have the following button which opens a dialog box of filechooser, can someone tell me how to restrict the user to choose only .xml file?

 Load.addActionListener(new ActionListener()
               {
                     public void actionPerformed(ActionEvent e)
                       {
                              //Handle open button action.
                     if (e.getSource() == Load)
                      {
                         int returnVal = fc.showOpenDialog(GUI.this);
                         if (returnVal == JFileChooser.APPROVE_OPTION)
                           {
                              File file = fc.getSelectedFile();
                             
                              printStats("Loaded successfully: " + file.getName() + "." + "\n");
                           }               
                          }
                     }
               }
             );
0
jtcy
Asked:
jtcy
  • 5
  • 4
  • 3
1 Solution
 
CEHJCommented:
Use a FileFilter
0
 
CEHJCommented:
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
zzynxSoftware engineerCommented:
0
 
jtcyAuthor Commented:
Actually, i was just from that page. The example it gives there uses many classes, i was wondering if there is an easier way to do. hm~
0
 
CEHJCommented:
There are just two classes in the example i mentioned
0
 
zzynxSoftware engineerCommented:
See my previous comment
0
 
jtcyAuthor Commented:
Yup, that was exactly what I wanted.
0
 
zzynxSoftware engineerCommented:
Thanks
0
 
CEHJCommented:
LOL and the difference between that and what i'd already posted is ..?
0
 
jtcyAuthor Commented:
Problem Problem~~

Um....apparently the directory that shown when the dialog box first opened is mydocument, how can i set it to be the directory that current class file is from?

p/s: Sorry CEHJ, I only had 20 points here, cant split them, but thanks anyway.

0
 
zzynxSoftware engineerCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now