File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to scan a list of files in current directory using JFileChooser ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to scan a list of files in current directory using JFileChooser ??" Watch "How to scan a list of files in current directory using JFileChooser ??" New topic
Author

How to scan a list of files in current directory using JFileChooser ??

Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
I need to parse the files in the current directory into a menu that displays either txt or java source files to be displayed in a text area.

I'm getting several these errors:



JFileChooser chooser = new JFileChooser(getCurrentDirectory());

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791

This one says the method getCurrentDirectory() isn't found. With this syntax the compiler is looking in the current class and if you didn't write it, it ain't there.

And this one says the method is actually on JFileChooser, but you need to create an instance to call the method.

Try this and let us know if it does what you expect ...


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Phil Powell
Greenhorn

Joined: Jul 13, 2004
Posts: 26
Well, I tried EXACTLY what you recommended:

import javax.swing.*;

JFileChooser fc = new JFileChooser();
System.out.println(fc.getCurrentDirectory());

I get:

Cannot find symbol
Symbol: method getCurrentDirectory
Class: JFileChooser

In fact I can't use a single solitary JFileChooser property nor method without the "cannot find symbol" compiler error every time

Phil
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

So this "JFileChooser" class you're using: is it the javax.swing.JFileChooser class, or is it a JFileChooser class you wrote yourself and put into your default (not in a package) directory? Your error message suggests the latter.
Phil Powell
Greenhorn

Joined: Jul 13, 2004
Posts: 26
NO, consider this:

/*
* Stuff.java
*
* Created on January 22, 2007, 3:54 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import javax.swing.*;
/**
*
* @author ppowell-c
*/
public class Stuff {
/** Creates a new instance of Stuff */
public Stuff() {
}

public static void main(String[] args) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Blah");
}
}


Also produces "cannot find symbol" error. And I'm importing all of javax.swing.*

Phil
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

But if you had a class in the default package named JFileChooser then the compiler would use that regardless of what you imported from named packages. Look (or look again, if you didn't look before) to see if you did that.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Originally posted by Phil Powell:
NO, consider this:

Also produces "cannot find symbol" error. And I'm importing all of javax.swing.*

Phil


It compiles fine for me...

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Originally posted by Paul Clapham:
But if you had a class in the default package named JFileChooser then the compiler would use that regardless of what you imported from named packages. Look (or look again, if you didn't look before) to see if you did that.


One quick way to tell, if there is another JFileChooser in conflict, is to not use import. Use the fully qualified name, and see if it works.



Henry
Phil Powell
Greenhorn

Joined: Jul 13, 2004
Posts: 26
That was exactly it! Embedded in a hidden subdirectory to boot!
 
Don't get me started about those stupid light bulbs.
 
subject: How to scan a list of files in current directory using JFileChooser ??