各位老大帮帮忙,找了半天也没有发现给JFileChooser 里面的撤销按钮加事件的地方,还有就是那个JTextField里面怎么设置文件名啊?
解决方案 »
- 这个程序有哪些语法错误,帮忙啊
- 学习java
- 求java代码:用分支限界法求解装载问题,
- 大家帮帮我 !
- 求Cay S.Horstmann,Gary Cornell的《Java 2 核心技术 卷II:高级性能》电子版,最好是中文的(100分,急~~!)
- 提问:SWT的的composite为什么无法滚动?
- 请问用java怎么读取分割.asf文件(流媒体文件)
- 在JBuilder7中制作的exe问题
- JScrollPane的问题。在线等待
- 线程锁与if结合使用时出现的问题。。这到底是为什么呢?
- 本来想让一个球移动,怎么变成一条直线了
- static int x1 = prt("x1");是什么意思?
你直接给jFileChooser加就行了。
或者用int n = fc.showOpenDialog(this);
if (n == JFileChooser.APPROVE_OPTION) {}
else if (n == .....
做处理
jFileChooser.setSelectedFile可以设置textfield里面的文件名。
int returnVal = jf.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
//添加点击打开按钮后的事件
} else {
//添加点击撤销按钮后的事件
}
JTextField里的文件名不是会自动根据你所选的文件设上去的吗?不需要你自己设啊
------------------------------------
体验速度,体验CSDN新版论坛助手:http://community.csdn.net/Expert/TopicView.asp?id=3108679
{}
if (n == JFileChooser.APPROVE_OPTION) {}
else if (n == .....
我运行类似的代码,然后出现的对话框中,我选中一个txt文档,按“打开”,然后不停的出现这个对话框,根本打不开那个txt文档,为啥呢?
private JTextField
filename = new JTextField(),
dir = new JTextField();
private JButton
open = new JButton("Open"),
save = new JButton("Save");
private JEditorPane ep = new JEditorPane();
private JScrollPane jsp = new JScrollPane();
private File file;
class OpenL implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser c = new JFileChooser();
c.setFileFilter(new TextFileFilter());
// Demonstrate "Open" dialog:
int rVal = c.showOpenDialog(FileAccessApplet.this);
if(rVal == JFileChooser.APPROVE_OPTION) {
file = c.getSelectedFile();
filename.setText(file.getName());
dir.setText(c.getCurrentDirectory().toString());
try {
System.out.println("Url is " + file.toURL());
ep.setPage(file.toURL());
// ep.repaint();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
if(rVal == JFileChooser.CANCEL_OPTION) {
filename.setText("You pressed cancel");
dir.setText("");
} else {
save.setEnabled(true);
}
}
}
class SaveL implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser c = new JFileChooser(file);
c.setSelectedFile(file);
// Demonstrate "Save" dialog:
int rVal = c.showSaveDialog(FileAccessApplet.this);
if(rVal == JFileChooser.APPROVE_OPTION) {
filename.setText(c.getSelectedFile().getName());
dir.setText(c.getCurrentDirectory().toString());
try {
FileWriter fw = new FileWriter(file);
ep.write(fw);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
if(rVal == JFileChooser.CANCEL_OPTION) {
filename.setText("You pressed cancel");
dir.setText("");
}
}
}
}