Solved

Problem with JFileChooser.

Posted on 2001-09-04
24
229 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:

911 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

19 Experts available now in Live!

Get 1:1 Help Now