• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser takes so long ....!!

 
Kamal Nassili
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm working on the scjd, and for my training i'm using the code from Monkhouse book to open a dialogue in order to select the location file of the database. the problem i found is that the dialogue takes too long time to open(IT TAKES 42 SECONDS TO OPEN !!!....pfieeeew) and it takes same thing each time i try to go inside a directory or sub-directory. my question is: is that normal ? does anybody had the same problem? is there any particular thing i had to do on my system?
it's not very funny to have to wait for 42 seconds each time i click on a directory in the FileChooser dialoque during my testing. And sincerely i began to doubt if i have made a good choice in adopting java as my prefered language....
please any answer ?
following is the class concerned by the file selection dialoque:

-----------------------------------------------------------------
private class BrowseForDatabase implements ActionListener {
/** {@inheritDoc} */
public void actionPerformed(ActionEvent ae) {
JFileChooser chooser
= new JFileChooser(System.getProperty("user.dir"));
chooser.addChoosableFileFilter(
new javax.swing.filechooser.FileFilter() {
/**
* display files ending in ".db" or any other object
* (directory or other selectable device).
*/
public boolean accept(File f) {
if (f.isFile()) {
return f.getName().endsWith(DATABASE_EXTENSION);
} else {
return true;
}
}

/**
* provide a description for the types of files we are
* allowing to be selected.
*/
public String getDescription() {
return DATABASE_FILE_CHOOSER_DESCRIPTION;
}
}
);

// if the user selected a file, update the file name on screen
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(null)) {
locationField.setText(chooser.getSelectedFile().toString());
location = locationField.getText();
updateObservers(OptionUpdate.Updates.DB_LOCATION_CHANGED,
location.trim());
}
}
}
-----------------------------------------------------------------
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it also slow if you remove the FileFilter?
 
Kamal Nassili
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did'nt try it without the FileFilter, but i think it's not supposed to be so slow (42 seconds with a timer in my hand) even with a FileFilter since a file chooser is supposed to have filtering capabilities.
Should'i remove the FileFilter?
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off course it is not supposed to be slow, but if you want to find out the problem I suggest experimenting with the FileChooser. One of the experiments you might to do is trying it without the FileFilter. Making an SSCCE (Short, Self Contained, Correct (Compilable), Example) will also help.
 
Kamal Nassili
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,
i'll experimente all that and informe you after. thanks for your suggestions.
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your welcome, good luck and have fun while experimenting!
 
Kamal Nassili
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jethro,
I ran the code below(without any FileFilter), and got the same incredibly long delay to open the file chooser.
---------------------------------------------------------------------
public void actionPerformed(ActionEvent ae) {
JFileChooser chooser
= new JFileChooser(System.getProperty("user.dir"));
// if the user selected a file, update the file name on screen
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(null)) {
locationField.setText(chooser.getSelectedFile().toString());
location = locationField.getText();
}
}
--------------------------------------------------------------------
thanks
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're still not following the guidelines at http://homepage1.nifty.com/algafield/sscce.html . Please create an example that really runs, and we might be able to help you.
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you want try with different computer / laptop.

Jeffry Kristianto Yanuar (Java Instructor)
SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2) --> Waiting for the result
 
Kamal Nassili
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,
I FIXED THE PROBLEM!
It was a BUG in jdk1.6.0_07 and prior versions (I found that in "Bugs Database of Sun website"). So i fixed that by downloading the latest version of jdk witch is jdk1.6.0_10.
Now the FeleChooser works FINE !
Thanks to you ALL for your responses and advises.
Thanks also to Sun for fixing the problem: finally Java is fine.
Thanks.
 
Kamal Nassili
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean the FileChooser works fine !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic