Solved

FileChooser

Posted on 2004-09-21
12
159 Views
Last Modified: 2010-03-31
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
Comment
Question by:jtcy
  • 5
  • 4
  • 3
12 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Use a FileFilter
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
0
 
LVL 37

Accepted Solution

by:
zzynx earned 20 total points
Comment Utility
0
 

Author Comment

by:jtcy
Comment Utility
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
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
There are just two classes in the example i mentioned
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 37

Expert Comment

by:zzynx
Comment Utility
See my previous comment
0
 

Author Comment

by:jtcy
Comment Utility
Yup, that was exactly what I wanted.
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
LOL and the difference between that and what i'd already posted is ..?
0
 

Author Comment

by:jtcy
Comment Utility
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
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now