【问题标题】:How to open a folder windows in java aplication ? I want to insert path of file .txt in my application如何在java应用程序中打开文件夹窗口?我想在我的应用程序中插入文件 .txt 的路径
【发布时间】:2015-12-24 17:25:30
【问题描述】:

如何制作一个可以打开文件夹选项和搜索.txt文件的按钮。 如果文件夹选项,我想通过打开窗口插入路径(例如:c:/documents)。所以我的应用程序的用户只需单击它,而不是在字段文本中输入它。 顺便说一句,我使用 netbeans 作为我的 IDE。 请帮我。谢谢。

【问题讨论】:

标签: java path window directory


【解决方案1】:

这可以通过 JFileChooser 来完成。 Official Tutorial 是最好的起点。

重要的步骤是:

JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多