Solved

Problem with JFileChooser.

Posted on 2001-09-04
24
237 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 196
servlet  URL Rewriting 1 38
how to see all occupied ports on windows 10 laptop 15 66
Java exception bubble up 2 18
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

832 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