如何制作’打开’对话框?

我制作了一个搜索.txt文件的程序。

如果我单击一个文件,则表示应该出现“打开方式”对话框,该对话框将包含所有已安装程序的列表。

我正在使用此代码搜索文件:

public File[] finder( String dirName) { // Create a file object on the directory. File dir = new File(dirName); // Return a list of all files in the directory. return dir.listFiles(new FilenameFilter(); } public boolean accept(File dir, String filename) { return filename.endsWith(".txt"); } 

我可以使用哪些Java代码来显示“打开方式”对话框?

你应该使用FileChooser 。 看看这里 :

 //Create a file chooser final JFileChooser fc = new JFileChooser(); ... //In response to a button click: int returnVal = fc.showOpenDialog(aComponent); 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); } } ... } 

我可以使用哪些Java代码来显示“打开方式”对话框?

据我所知,J2SE中没有任何内容。 OTOH Desktop API可以在任何应用程序中打开File 。 是默认的消费者。

您可以为此目的创建自己的对话框。如果要获得程序列表.on Windows,您可以使用注册表。 请参阅此链接通过注册表检测已安装的程序

并检查如何使用Java通过Java 读取/写入Windows注册表来访问注册表