Solved

Problem with JFileChooser.

Posted on 2001-09-04
24
252 Views
Last Modified: 2012-06-21
Hi all,
one problem in JFileChooser.
When I use it as
JFileChooser filechooser=new JFileChooser();
Its takes time and searches the A drive also.
If there is no such drive it shows "A drive not found....... Abort,Retry...).How to solve this problem
of not searching the A drive.
When the applet is run in Explorer No problem.
But this problem arises only when I make use of AppletViewer
0
Comment
Question by:maheswari
  • 7
  • 6
  • 6
  • +4
24 Comments
 

Author Comment

by:maheswari
ID: 6455579
Help is required at the earliest.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6455646

0
 

Author Comment

by:maheswari
ID: 6455650
hi sudhakar koundinya,

u had posted without anything ? forgot to post ?
0
Independent Software Vendors: 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 4

Expert Comment

by:Oliver_Dornauf
ID: 6455739
Hi maheswari, I had the same problem with JFileChoose. Is is e windows specific problem, because the JFileChooser seeks every root partion. (A: is a root partition)
I did not solve the problem because because less time :-)
but I think it deals with the "FileSystemView". (see ctor)
with instanciates a WindowsFileSystemView. Mybee you write your derived FileSystemView.

0
 
LVL 92

Expert Comment

by:objects
ID: 6455762
You just need to call:

chooser.setCurrentDirectory("c:\");

Or somehwere other than a:
0
 

Author Comment

by:maheswari
ID: 6455838
I set a current directory, even then it is resulting by searching a: drive. How to proceed ?
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 6455956
maheswari the JFileCooser get by default every root partition.
Modify the tip form objects an try new JFileChooser ("c:");


0
 

Author Comment

by:maheswari
ID: 6456126
I also did like this. Unable to solve the problem of searching drive a:

how to proceed ?
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 6456150
yepp, write your own FileSystemView or (like me) live with the problem :-)

I think the problem is systems inherent in windows. Solve it (write your own FileSystemView) is hard work. But you should look in the implemention javax.swing.filechooser.FileSystemView.

you will find a function getRoots in the inner class WindowsFileSystemView, it contains:
>
FileSystemRoot floppy = new FileSystemRoot("A" + ":" + "\\");
         rootsVector.addElement(floppy);
<

Derive a new FileSystemView class and override the getRoot.

hope it helps.

0
 

Expert Comment

by:muhotrepius
ID: 6456213
Interesting !? I've never had this problem on my NT. What OS are you using ?? I've just tried this and it works fine

import javax.swing.*;
class FCH {
   public static void main(String[] a) {
      JFileChooser chooser = new JFileChooser();
       int returnVal = chooser.showOpenDialog(null);
       if(returnVal == JFileChooser.APPROVE_OPTION) {
          System.out.println("You chose to open this file: " +
               chooser.getSelectedFile().getName());
       }
   }//main
}
0
 
LVL 9

Expert Comment

by:yongsing
ID: 6456221
That's strange. I don't have this problem on NT and Win 98.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6456483
Hi maheshwari
Sorry for that blank message.

I tried your problem

In some systems it is working fine.
In some systems i got same error what you have noticed.
Hope I may rectify this problem and give u solution

Cheers
Sudhakar

0
 

Author Comment

by:maheswari
ID: 6463043
Have u got any solution ? mail me
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 6463071
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 6463072
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 6463075
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 50 total points
ID: 6463445
public void goTo (File f)
{
    if (f == null) return;
    if (!f.exists()) return;
    if (chooser == null) return;

    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    javax.swing.filechooser.FileFilter filter = chooser.getFileFilter();
    if (filter != null)
    {
        if (!filter.accept(f))
        {
            javax.swing.filechooser.FileFilter all =
                chooser.getAcceptAllFileFilter();
            chooser.setFileFilter(all);
        }
    }

    File parentFolder = f.getParentFile();
    if (parentFolder != null) chooser.setCurrentDirectory(parentFolder);


    chooser.setSelectedFile(null);


    chooser.setSelectedFile(f);

    chooser.invalidate();
    chooser.repaint();
}


Will the above idea Helps u ?
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6463486
Okay One thing tell me

what is the version of JDK you are using.Because In our comany we are using  three versions.May be one of the version's bug(I don't know exactly).But i will try ur solution

Cheers
Koundinya :-)

0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6463490
Okay One thing tell me

what is the version of JDK you are using.Because In our company we are using  three versions.May be one of the version's bug(I don't know exactly).But i will try ur solution

Cheers
Koundinya :-)

0
 

Author Comment

by:maheswari
ID: 6484532
I have jdk1.3 and I still face the same problem.

It works fine with JWindow or JFrame

but creates problem only with JApplet and also consumes lot of time during initialisation

Best Regards,
Anu-Maheswari
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 6486670
Try to modify ut policy file using policytool for the file permissions

bye
Koundinya
0
 
LVL 20

Expert Comment

by:Venabili
ID: 8908231
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- points for sudhakar_koundinya

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venabili
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8940155
OK and thanks
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 52
How do I remove an object from a 3 51
Java basic valueOf question 1 32
Github api to fetch the number of collaborators in a git repo 1 25
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

685 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