我是 Java 编程新手,正在构建一个应用程序,该应用程序将添加、显示和删除给定文件夹位置中的文件。
我已经使用 JFileChooser 添加了文件,并且知道如何删除这些文件。然而我被显示部分困住了。
我想在我的应用程序中使用不同的图标显示文件和文件夹。我尝试在显示面板内添加 JFileChooser 并禁用对话框的按钮和菜单组件,但没有成功。有没有更好的方法来做到这一点?
我更喜欢下面的方式。
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
在自己的窗口中弹出。
我通常从内部调用它JButton
's ActionListener
code.
fileChooseButton.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
// File chooser code goes here usually
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)