?
Solved

FileChooser

Posted on 2004-09-21
12
Medium Priority
?
168 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
ID: 12111285
Use a FileFilter
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12111292
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 37

Accepted Solution

by:
zzynx earned 80 total points
ID: 12111297
0
 

Author Comment

by:jtcy
ID: 12111301
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
ID: 12111312
There are just two classes in the example i mentioned
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12111313
See my previous comment
0
 

Author Comment

by:jtcy
ID: 12111339
Yup, that was exactly what I wanted.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12111349
Thanks
0
 
LVL 86

Expert Comment

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

Author Comment

by:jtcy
ID: 12120991
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month17 days, 9 hours left to enroll

829 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