我想在FileDialog中实现文件过滤功能,代码如下:
class Myfilter implements FilenameFilter//用于文件过滤
{
public boolean accept(File dir,String fname)
{
return fname.toLowerCase().endsWith(".txt");
}
} public void jButton_actionPerformed(ActionEvent e)//单击按钮Button打开文件对话框
{
FileDialog fdlg=new FileDialog(this,"打开", FileDialog.LOAD);
Myfilter filter=new Myfilter();
fdlg.setFilenameFilter(filter);
fdlg.setVisible(true);
}但是却不能实现我想要的功能,打开文件对话框后,过滤条中的信息仍然是(*.*),哪位大哥能帮帮小妹呢?
class Myfilter implements FilenameFilter//用于文件过滤
{
public boolean accept(File dir,String fname)
{
return fname.toLowerCase().endsWith(".txt");
}
} public void jButton_actionPerformed(ActionEvent e)//单击按钮Button打开文件对话框
{
FileDialog fdlg=new FileDialog(this,"打开", FileDialog.LOAD);
Myfilter filter=new Myfilter();
fdlg.setFilenameFilter(filter);
fdlg.setVisible(true);
}但是却不能实现我想要的功能,打开文件对话框后,过滤条中的信息仍然是(*.*),哪位大哥能帮帮小妹呢?
解决方案 »
- 用Java做一个聊天程序!
- Partent t3=(Partent) t;
- 一个关于Cookie和Session的问题
- [我能说服你们嘛?]关于面向对象的种种概念
- wait()h和notify()用法的线程同步问题?
- 【转载】Java语言学习要点
- 低分请教:何谓“重载”?
- Exception in thread "main" java.lang.NoClassDefFoundError: app 这个错误是什么意思?????
- 一切后果怎想象,如常望你但觉冰凉!!!开始Q吧!
- 請問一個關於"\u"的問題
- 想做个网站,不知道怎么入手,请教!
- 请问20957.0 * 1142.61的结果用什么类型表示啊?
楼主也可以考虑用JFileChooser
JFileChooser不是用来选择文件的吗
fdlg.setFileName("*.txt");
不过只能过虑文件的类型不能具体到某个文件
public void setFilenameFilter(FilenameFilter filter)Sets the filename filter for this file dialog window to the specified filter. Filename filters do not function in Sun's reference implementation for Windows 95, 98, or NT 4.0.
你的机器是什么系统的?我是2003试了也不行,才看到这个。