Solved

FileChooser

Posted on 2004-09-21
12
161 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 37

Expert Comment

by:zzynx
ID: 12111290
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12111292
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 37

Accepted Solution

by:
zzynx earned 20 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
 
LVL 37

Expert Comment

by:zzynx
ID: 12121019
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
starter POM and spring-boot-starter,  spring-boot-web 2 53
netstat -ano | find "8000" and taskkill /f /pid 2984 3 55
fibonacci ten numbers 4 38
Java string replace 11 43
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

815 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