simple help about JFileChooser

D

dreamtackler

here is a method i writte in java
public void aaa(){
JFileChooser chooser=new JFileChooser();
chooser.setFileFilter(new FileFilter() {//
setFileFilter(javax.swing.Filechooser.filefilter)
//in javax.swing.JFileChooser can't applied to (<anonymous
java.io.fileFilter>)
public boolean accept(File f) {
String fileName = f.getName().toLowerCase();
return fileName.endsWith(".txt") || f.isDirectory();
}
public String getDescription() {
return "Text Files";
}
});
chooser.showOpenDialog(this);
}

when used in some class it run well.but when it appear in some
class,it goes wrong .the IDE tell me that
setFileFilter(javax.swing.Filechooser.filefilter)
//in javax.swing.JFileChooser can't applied to (<anonymous
java.io.fileFilter>).
who can tell me what's that means. and why that happenes(happen)?
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) schreef:
| here is a method i writte in java
| public void aaa(){
| JFileChooser chooser=new JFileChooser();
| chooser.setFileFilter(new FileFilter() {//
| setFileFilter(javax.swing.Filechooser.filefilter)
| //in javax.swing.JFileChooser can't applied to (<anonymous
| java.io.fileFilter>)
| public boolean accept(File f) {
| String fileName = f.getName().toLowerCase();
| return fileName.endsWith(".txt") || f.isDirectory();
| }
| public String getDescription() {
| return "Text Files";
| }
| });
| chooser.showOpenDialog(this);
| }
|
| when used in some class it run well.but when it appear in some
| class,it goes wrong .the IDE tell me that
| setFileFilter(javax.swing.Filechooser.filefilter)
| //in javax.swing.JFileChooser can't applied to (<anonymous
| java.io.fileFilter>).
| who can tell me what's that means. and why that happenes(happen)?

Java is case sensitive. FileChooser != filechooser. Probably
filefilter is a local variable in FileChooser, which is unaccessible.
Try javax.swing.filechooser.FileFilter.

Please copy and paste error messages, do not type them by hand. The
error message you give does not make sense.

Read the link in my sig.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFIExYee+7xMGD3itQRAu2DAJ9X41v6i0hWBTQnua9uGz9j45vvUQCfXDh4
UB1oEOs2WzpqbnlC8A6MCZU=
=5OwE
-----END PGP SIGNATURE-----
 
D

dreamtackler

public void aaa(){
JFileChooser chooser=new JFileChooser();
chooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
String fileName = f.getName().toLowerCase();
return fileName.endsWith(".txt") || f.isDirectory();
}
public String getDescription() {
return "Text Files";
}
});
chooser.showOpenDialog(this);
}

oh,god ,i am sure there is no mistake in my mthhod on case sensitive.
i just copy it from a class to another class .and it go wrong and the
IDE
said that in javax.swing.JFileChooser can't applied to (<anonymous
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) schreef:
| public void aaa(){
| JFileChooser chooser=new JFileChooser();
| chooser.setFileFilter(new FileFilter() {
| public boolean accept(File f) {
| String fileName = f.getName().toLowerCase();
| return fileName.endsWith(".txt") || f.isDirectory();
| }
| public String getDescription() {
| return "Text Files";
| }
| });
| chooser.showOpenDialog(this);
| }
|
| oh,god ,i am sure there is no mistake in my mthhod on case sensitive.
| i just copy it from a class to another class .and it go wrong and the
| IDE
| said that in javax.swing.JFileChooser can't applied to (<anonymous
|> | java.io.fileFilter>).

I asked you to copy over the ERROR MESSAGE. The above definitely is not
what your compiler or IDE is telling you, or it must be a very bad one.

Did you read the link below? Note that it is very much appreciated here
if at least you try to use proper English.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFIEytIe+7xMGD3itQRAjh4AJsEb+35V2vn6Y19GXpE5sEWwIL6xgCfUEJA
yxL5vM/0vtC/W8z1EwU2hig=
=+7yf
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,274
Latest member
JessMcMast

Latest Threads

Top