Solved

FileChooser

Posted on 2004-09-21
12
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 60
hibernate insert example 13 40
Unhandled exception type Exception 18 52
JDBC performance 8 29
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

730 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