• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jesse Crockett
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ...
 
Phil Powell
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was exactly it! Embedded in a hidden subdirectory to boot!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic