在JFileChooser中仅打开.xml文件 [英] Open only .xml file in JFileChooser

查看:135
本文介绍了在JFileChooser中仅打开.xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个java应用程序,我只需要 .xml 文件。现在,只要用户想要保存文件或打开现有文件,我只想在 JFileChooser 中显示 .xml 文件。

I am developing a java application for which I need only .xml files. Now I want to show only .xml files in JFileChooser whenever user wants to save a file or open a existing file.

这可能只显示 .xml 个文件吗?

Is this possible to show only .xml files?

推荐答案

您可以使用JFileChooser API来完成任务。

You can use JFileChooser API to achieve your task.

仅适用于打开.xml文件

For Open only .xml file

// create a filechooser;
JFileChooser chooser = new JFileChooser(cwd);
FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter(
     "xml files (*.xml)", "xml");

chooser.setDialogTitle("Open schedule file");
// set selected filter
chooser.setFileFilter(xmlfilter);

此外,请浏览javax.swing.filechooser.FileNameExtensionFilter。

Also, go through javax.swing.filechooser.FileNameExtensionFilter.

这篇关于在JFileChooser中仅打开.xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆