java图形界面中定义一个“浏览”按钮,点击可以打开选择文件的对话框

Elvis_欧元_ 2011-07-13 01:54:22
如图,如图在java图形界面中定义一个“浏览”按钮,点击可以打开选择文件的对话框,而且选择文件确定后可以把文件路径打印到textField中。具体要怎么写?

...全文
502 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangneng100 2011-07-13
  • 打赏
  • 举报
回复
JFileChooser fc = new JFileChooser();
...
public void actionPerformed(ActionEvent e) {
//Handle open button action.
if (e.getSource() == openButton) {
int returnVal = fc.showOpenDialog(FileChooserDemo.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//This is where a real application would open the file.
log.append("Opening: " + file.getName() + "." + newline);
} else {
log.append("Open command cancelled by user." + newline);
}
} ...
}

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧