Solved

Problem with JFileChooser.

Posted on 2001-09-04
24
259 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
[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
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

688 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