JavaSE怎么实现浏览按钮,点击出现windows资源管理器选择文件。
求大神给个思路,怎么实现。

解决方案 »

  1.   

    用FileDialog可以做,JFileChooser也可以做。
    参见:
    http://www.iteye.com/topic/1116890
      

  2.   

    JButton jbfile=new JButton();
    JTextField jtfile=new JTextField("",10);jbfile.addActionListener(new ImportFrame_jbfile_actionAdapter(this));
          public void jbfile_actionPerformed(ActionEvent e) { 
    //建立文件选择框对象
    JFileChooser fc=new JFileChooser();
    //设定文件选择框标题
    fc.setDialogTitle("Open class File");
    //显示文件选择框,在选择后将结果储存到returnVal变量中
    int returnVal = fc.showOpenDialog(this.getComponent(0));
    //如果用户选择了文件,并点击了"Opne/打开"按钮,显示用户选择的文件全名路径,
    //如果用户点击"Close/关闭"按钮,以及其它方式退出文件选择框,则什么也不做。
    if (returnVal == JFileChooser.APPROVE_OPTION){
    File file = fc.getSelectedFile();
    jtfile.setText(file.getPath()); 
    }   
          }
    class ImportFrame_jbfile_actionAdapter implements ActionListener {
        private ImportFrame adaptee;
        ImportFrame_jbfile_actionAdapter(ImportFrame
                adaptee) {
            this.adaptee = adaptee;
        }    public void actionPerformed(ActionEvent e) {
            adaptee.jbfile_actionPerformed(e);
        }
    }
      

  3.   

    JButton jbfile=new JButton();
    JTextField jtfile=new JTextField("",10);jbfile.addActionListener(new ImportFrame_jbfile_actionAdapter(this));
          public void jbfile_actionPerformed(ActionEvent e) { 
        //建立文件选择框对象
        JFileChooser fc=new JFileChooser();
        //设定文件选择框标题
        fc.setDialogTitle("Open class File");
        //显示文件选择框,在选择后将结果储存到returnVal变量中
        int returnVal = fc.showOpenDialog(this.getComponent(0));
        //如果用户选择了文件,并点击了"Opne/打开"按钮,显示用户选择的文件全名路径,
        //如果用户点击"Close/关闭"按钮,以及其它方式退出文件选择框,则什么也不做。
        if (returnVal == JFileChooser.APPROVE_OPTION){
        File file = fc.getSelectedFile();
        jtfile.setText(file.getPath()); 
        }   
          }
    class ImportFrame_jbfile_actionAdapter implements ActionListener {
        private ImportFrame adaptee;
        ImportFrame_jbfile_actionAdapter(ImportFrame
                adaptee) {
            this.adaptee = adaptee;
        }    public void actionPerformed(ActionEvent e) {
            adaptee.jbfile_actionPerformed(e);
        }
    }
      

  4.   

    如果是文件选择框的话有现成的就是JFileChooser
    树状结构的话就用JTree