Solved

Problem with JFileChooser.

Posted on 2001-09-04
24
221 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
Comment Utility
Help is required at the earliest.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility

0
 

Author Comment

by:maheswari
Comment Utility
hi sudhakar koundinya,

u had posted without anything ? forgot to post ?
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
Comment Utility
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
Comment Utility
You just need to call:

chooser.setCurrentDirectory("c:\");

Or somehwere other than a:
0
 

Author Comment

by:maheswari
Comment Utility
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
Comment Utility
maheswari the JFileCooser get by default every root partition.
Modify the tip form objects an try new JFileChooser ("c:");


0
 

Author Comment

by:maheswari
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
That's strange. I don't have this problem on NT and Win 98.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
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
Comment Utility
Have u got any solution ? mail me
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
Comment Utility
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
Comment Utility
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
Comment Utility
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Try to modify ut policy file using policytool for the file permissions

bye
Koundinya
0
 
LVL 20

Expert Comment

by:Venabili
Comment Utility
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
Comment Utility
OK and thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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 …
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

763 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

12 Experts available now in Live!

Get 1:1 Help Now