如何在Java应用程序中添加文件浏览器? [英] How do I add a file browser inside my Java application?

查看:127
本文介绍了如何在Java应用程序中添加文件浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java程序员的新手,正在构建一个应用程序,它将添加,显示和删除给定文件夹位置的文件。

I am new to Java progamming and am building a application that will add, display and remove files from a given folder location.

我使用JFileChooser添加了文件知道如何删除文件。但是我被显示部分卡住了。

I have added files using JFileChooser and know how to delete the files. However I am stuck with the display portion.

我想在我的应用程序中使用不同的图标显示文件和文件夹。我试图在显示面板中添加一个JFileChooser并禁用对话框的按钮和菜单组件,但我还没有成功。有没有更好的方法呢?

I want to display the files and folder using different icon inside my application. I tried to add a JFileChooser inside the display panel and disable the button and menu components of the dialog box, but I have not succeeded. Is there any better way to do this?

推荐答案

我更喜欢以下方式。

JFileChooser chooser= new JFileChooser();

int choice = choose.showOpenDialog();

if (choice != JFileChooser.APPROVE_OPTION) return;

File chosenFile = chooser.getSelectedFile();

// You can then do whatever you want with the file.

调用此代码将导致 JFileChooser 到弹出自己的窗口。

Calling this code will cause a JFileChooser to popup in its own window.

我通常在 JButton 中调用它ActionListener 代码。

fileChooseButton.addActionListener( new ActionListener(){
    public void actionPerformed(ActionEvent e){

        // File chooser code goes here usually
    }
});

这篇关于如何在Java应用程序中添加文件浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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