如何制作’打开’对话框?
我制作了一个搜索.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注册表来访问注册表
- 透明JPanel
- 我们可以使用double来存储货币字段并使用BigDecimal进行算术运算
- java.util.MissingResourceException:找不到基本名称消息的bundle,locale en_US
- 从具有子类的抽象类实现Comparable接口
- 为什么在java.util.Comparator中实现equals不是必须的?
- WSIT / Metro不了解Security SOAP标头
- 如何使用Servlet在其Response中显示一个JSP页面?
- 为什么java安全管理器不禁止创建新的Thread()也不禁止它?
- 降级Eclipse ant以在使用旧的JDK库时进行编译(Java 1.7 – > 1.6)